vue3-模板语法

 

模板语法

插值:插入文本,原始Html,表达式(计算函数)

如:html代码变量chazhi插入div中

 

指令:比如v-model绑定输入值和变量msg

   v-for遍历渲染

   @click点击事件

 

 

<!DOCTYPE html>
<html>
    <head>
        
        <meta charset="utf-8">
        <title>vue1</title>
        <script src="vue.js"></script>
        <link rel="stylesheet" type="text/css" href="vue.css">
    
    </head>
    <body>
        
        
        <div id="app">
            <div id="test">{{test}}</div>
            <div v-html="chazhi"></div>

            <div>
                <input type="text" v-model="msg">
                <button @click="submit">submit</button>
                <ul>
                    <li v-for="item of list">{{item}}</li>
                </ul>
            </div>
        </div>        
        <script>
            var app=new Vue({
                el:"#app",
                data:{
                    test:'我是test',
                    chazhi:`<div>chzhi context</div>`,
                    list:[],
                    msg:""
                
                },
                methods:{
                    demo:function(){

                    },
                    submit:function(){
                        this.list.push(this.msg),
                        this.msg=""
                    }

            

                },
                beforeCreate:function(){
                        console.log("我是挂载函数")
                    }
                
            })        
        </script>
    </body>
</html>

 

posted @ 2020-04-03 14:06  JinweiChang  阅读(1280)  评论(0编辑  收藏  举报