4 vue安装

2020-08-27  本文已影响0人  滔滔逐浪
image.png

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>初始化helloworld</title>
    <script src="../js/vue.js"></script>
</head>
<body>

<div id="app">
{{message}}
    <h1>{{name}}</h1>
</div>
<script>

const app=new Vue({
    el: '#app',//用于挂载要管理 的数据
    data:{
        //定义数据
        message:"hellow",
        name:"22"
    }
})
</script>
</body>
</html>

v-for指令

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>遍历列表</title>
    <script src="../js/vue.js"></script>
</head>
<body>
<div id="app">
    {{message}}</br>
    <ul>
        <li v-for="item in movies">{{item}}</li>

    </ul>
</div>
<script>
    const app=new Vue({
        el:'#app',
        data:{
            message: "你好啊",
            movies: ['海豚湾',"海蜇","星际穿越"]
        }
    })

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


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue计数器</title>
    <script src="../js/vue.js"></script>
</head>
<body>
<div id="app">
 <h2>当前计数: {{counter}}</h2>
<!--    <button v-on:click="counter++">+</button>-->
<!--    <button v-on:click="counter&#45;&#45;">-</button>-->
    <button v-on:click="add">+</button>
    <button @click="sub">-</button>

</div>
<script>
 const  app=new Vue({
     el:"#app",
     data:{
         counter:0
     },
     methods:{
         add: function (){
             console.log("add被执行");
             this.counter++;
         },


     sub:function (){
         console.log("sub被执行");
         this.counter--;
     }
     },
 })
</script>
</body>
</html>


image.png
image.png
上一篇 下一篇

猜你喜欢

热点阅读