強制繫結css和style、條件渲染、列表渲染@2018-06-11
阿新 • • 發佈:2019-01-07
new Vue({
el: '#demo',
data: {
persons: [
{name: 'Tom', age:18},
{name: 'Jack', age:17},
{name: 'Bob', age:19},
{name: 'Mary', age:16}
]
},
methods: {
deleteP (index) {
this.persons.splice(index, 1) // 呼叫了不是原生陣列的splice(), 而是一個變異(重寫)方法
// 1. 呼叫原生的陣列的對應方法
// 2. 更新介面
},
updateP (index, newP) {
console.log('updateP', index, newP)
// this.persons[index] = newP // vue根本就不知道
this.persons.splice(index, 1, newP)
// this.persons = []
},
addP (newP) {
this .persons.push(newP)
}
}
})