美文网首页
2018-09-21

2018-09-21

作者: 月薪2k的前端程序员 | 来源:发表于2018-09-21 08:06 被阅读0次
<!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>

相关文章

网友评论

      本文标题:2018-09-21

      本文链接:https://www.haomeiwen.com/subject/smoonftx.html