[转] VUE 的常用指令2

v-on 事件绑定指令

 

 

以下代码效果是:点击按钮时,页面上的数字会 +1 

v-on:   可以简写为   @

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
      <h3>count 的值为:{{ count }}</h3>

      <button v-on:click="addCount">+1</button>
      <button @click="addCount">+1</button>
      <button @click="count += 2">+2</button>
    </div>

<script src="./lib/vue-2.6.12.js"></script>
<script>
    const vm = new Vue({
        el:'#app',
        data:{
            count: 0
        },
        methods:{
            addCount(){
                this.count += 1
            }
        }
    })
</script>

</body>
</html>

 

posted on 2022-10-18 20:19  z5337  阅读(26)  评论(0)    收藏  举报