1.v-for 的優先級比 v-if 更高,可以這樣用:
<li v-for="todo in todos" v-if="!todo.isComplete">
{{ todo }}
</li>
......
<ol>
<todo_item v-for='item in sites' v-bind:todo="item"></todo_item>
</ol>
<script>
.....
</script>
# 出現:component lists rendered with v-for should have explicit keys.的解決辦法:
# 將<todo_item v-for='item in sites' v-bind:todo="item"></todo_item> 修改為:
<todo_item v-for='item in sites':key="item" v-bind:todo="item"></todo_item>
2.由于 JavaScript 的限制,Vue 不能檢測以下變動的數組:
當你利用索引直接設置一個項時,例如:
vm.items[indexOfItem] = newValue
當你修改數組的長度時,例如:
vm.items.length = newLength
為了解決第一類問題,以下兩種方式都可以實現和 vm.items[indexOfItem] = newValue 相同的效果,同時也將觸發狀態更新:
// Vue.set
Vue.set(example1.items, indexOfItem, newValue)
// Array.prototype.splice
example1.items.splice(indexOfItem, 1, newValue)
為了解決第二類問題,你可以使用 splice:
example1.items.splice(newLength)
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。