vue自定義元件和列表迴圈--vue學習筆記
阿新 • • 發佈:2019-01-01
<div id="app">
<shaoyou v-for='item in listData' v-bind:myProps='item' v-bind:key='item.id'>
</shaoyou>
<button type="button" @click='add' name="button">Add</button>
</div>
Vue.component(
'shaoyou', {
props: ['myProps' ],
template: '<p>{{ item.id +". "+ item.text }}</p>'
}
)
var app = new Vue({
el: '#app',
data: {
listData: [{
id: 0,
text: '我會把手揣進褲兜'
}, {
id: 1,
text: '走到玉林路的盡頭'
}, ],
},
methods:{
add:function(){
app.listData.push({id: '新增',
text: '走過小酒館的門口'})
},
},
})