<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
li{
list-style: none;
}
</style>
</head>
<body>
<div id="app">
<my></my>
</div>
<script src="js/vue.js"></script>
<script>
Vue.component('my',{
template:`
<div>
<input type="text" v-model="wang">
<button v-on:click="nuo">添加</button>
<my2 v-bind:num="mass"></my2>
</div>
`,
data:function(){
return{
mass:['苹果','香蕉','鸭梨'],
wang:''
}
},
methods:{
nuo:function(){
this.mass.push(this.wang),
this.wang=""
}
}
})
Vue.component('my2',{
props:['num'],
template:`
<div>
<ul>
<li v-for="(w,index) in num">{{w}}<button v-on:click="lan(index)">删除</button></li>
</ul>
</div>
`,
methods:{
lan:function(index){
this.num.splice(index,1)
}
}
})
new Vue({
el:'#app'
})
</script>
</body>
</html>
网友评论