参考: Vue.js 组件
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue动态增删组件</title>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
</head>
<body>
<div id="app">
<button v-on:click="newItem()">新对象</button>
<input v-model="itemName">
<ol>
<todo-item v-for="item in sites" v-bind:todo="item"></todo-item>
</ol>
<button v-on:click="popItem">删除对象</button>
</div>
<script>
var toto_item = Vue.component('todo-item', {
props : [ 'todo' ],
template : '<li>{{ todo.text }}</li>'
})
var v = new Vue({
el : '#app',
data : {
sites : [ {
text : 'Runoob'
}, {
text : 'Google'
}, {
text : 'Taobao'
} ],
itemName : "newItemName"
},
methods : {
newItem : function() {
this.sites.push({
text : this.itemName
});
},
popItem : function() {
this.sites.pop();
}
}
})
</script>
</body>
</html>

被折叠的 条评论
为什么被折叠?



