Vue从父组件向子组件传递信息

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/vue.js"></script>
</head>
<body>
    <div id="app">
         <parent></parent>
    </div>
    <script>
        Vue.component('child',{
            template:`
            <div>
                <p :id="p1">{{str}}</p>
            </div>
            `,
            props:['p1','str'],
            methods:{
            }
        });

        Vue.component('parent',{
            template:`
                <div>
                    <child p1="p123" str="abc"></child>
                </div>
            `
        })
 
        var vm = new Vue({
            el:"#app"
        })
    </script>
 
</body>
</html>

  

 

 

 

posted @ 2021-02-26 12:00  田野与天  阅读(246)  评论(0编辑  收藏  举报