VUE组件的使用

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script src="./lib/vue-2.4.0.js"></script>
</head>
<body>
    <!-- 子组件 -->
    <template id="acount">
        <div>
            <!-- 在子组件展示父组件传递过来的数据 -->
            <!-- <h1>组件{{name1}}{{num}}</h1> -->
            <!-- 通过@click在子组件发送数据 -->
            <h1 @click="sendData">组件</h1>
        </div>
    </template>    

    <!-- 父组件 -->
    <div id="app">
        <!-- //在父组件绑定数据 -->
<!--         <acount1 :name1='name'></acount1>
        <acount1 :num='num'></acount1> -->

        <!-- //父组件定义方法接收数据 -->
        <acount1 v-on:send='getData'></acount1>
    </div>


<script >
    Vue.component("acount1",{
        template:"#acount",
        //在子组件接收父组件传递过来的数据
        // props:{
        //     name1:String,
        //     num:Number
        // },
        methods:{
            sendData(){
                this.$emit('send',123)
            }
        }
    });

    var vm=new Vue({
        el:"#app",
        data:{
            // name:"小小",
            // num:123
        },
        methods:{
            getData(value){
                console.log(value);
            }
        }
    })
</script>

</body>
</html>

 

posted @ 2022-08-01 10:49  小小野生程序员sunny  阅读(144)  评论(0编辑  收藏  举报