<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: '走过小酒馆的门口'})
},
},
})