欢迎阅读『Tag标签列表』

vue组件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./vuev2.5.21.js"></script>
</head>
<body>
    <div id="app">
            <input type="text" v-model="inputValue">
            <button @click="BtnClick">提交</button>
            <ul>
                <!-- <li v-for="item in list">{{item}}</li> -->
                <todo-item v-bind:content="item"  v-for="item in list"></todo-item>

            </ul>
    </div>
    <script>
        Vue.component("TodoItem",{
            props:["content"],
            template:"<li>{{content}}</li>"
        })
        var app= new Vue({
            el:"#app",
            data:{
                inputValue:"",
                list:[],
              
            },
            methods:{
                BtnClick:function(){
                //   console.log(this.list);
                this.list.push(this.inputValue);
                this.inputValue=""; 
                }
            }
        })
    </script>
    
</body>
</html>
v-dind:content="item" 向组件传递值
props=["content"] 接受组件的值
posted @ 2018-12-29 19:16  兔子零-A酱  阅读(177)  评论(0编辑  收藏  举报