Vue--基本语法

Vue语法学习

  1. 引入:script的src中导入vue包
  2. 创建:在script中创建vue对象
  3. 双向绑定:
  4. el----选择器,锁定标签
  5. data----定义变量,将标签内容绑定给变量
  6. {{变量}}----在标签中显示内容
  7. methods----绑定事件,控制变量内容。
<!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 type="text/javascript" src="js/vue.min.js"></script>
</head>
<body>
    <div  id="demo1"> 
        <div>{{msg}}</div>
        <button @click='fnChaMsg'>事件触发</button>
    </div>
    <!-- 引入vue 创建vue对象 双向绑定-->
    <script>
        var em = new Vue({
            el:'#demo1',
            data:{msg:'HI, Alice!'},
            methods:{
                fnChaMsg:function(){
                    this.msg = "Hello, alice!";

                }
            }
        })
    </script>   
</body>
</html>
 

猜你喜欢

转载自www.cnblogs.com/alicelai1319/p/10155505.html