vue之el与data的两种写法

<!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">
    <script type="text/javascript" src="../js/vue.js"></script>

    <title>el与data</title>
</head>
<body>
    <div id="root">
        <h1>
            你好,{{name}}
        </h1>

    </div>

    <script>
    //     //el的两种写法
    //     const v=new Vue({
    //      //   el:"#root",//第一种写法
    //         data:{
    //             name:"xiao bai"
    //         }
    //     })
    // v.$mount('#root');//第二种写法



     const v = new Vue({
              el:"#root",//第一种写法
            // data: {//data的第一种写法,对象式写法
            //     name: "xiao bai"
            // }
            data:function(){
                return{//函数写法
                    name:"xiao bai"
                }
            }
        })



    </script>
</body>
</html>

 

posted @ 2022-10-27 15:08  小白字太白  阅读(14)  评论(0编辑  收藏  举报