<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="app">
<my-father></my-father>
</div>
<script src="js/vue.js"></script>
<script>
Vue.component("my-father",{
template:`
<div>
<input type="text" v-model="meg">
<button @click="alt">添加</button>
<my-child v-bind:num="list"></my-child>
</div>
`,
data:function(){
return{
list:["吃饭","睡觉","打游戏"]
}
},
methods:{
alt:function(){
this.list.push(this.meg)
}
}
})
Vue.component("my-child",{
props:["num"],
template:`
<ul>
<li v-for="(value,index) in num">{{value}}<button @click="reg(index)">删除</button></li>
</ul>
`,
methods:{
reg:function(over){
this.num.splice(over,1)
}
}
})
new Vue({
el:"#app"
})
</script>
</body>
</html>
网友评论