v-on

强颜欢笑 提交于 2019-12-05 04:43:13
<body><div id="app">    <h2>{{counter}}</h2>    <button v-on:click="increament()">增加</button>    <button v-on:click="decreament()">减少</button></div><!--<button></button>--><script>   const app=new Vue({       el:'#app',       data:{           counter:0       },       methods:{           increament(){               return this.counter++;           },           decreament(){               return this.counter--;           }       }   })</script>v-on的语法糖:@
<button @click="increament()">增加</button><button @click="decreament()">减少</button>设置函数时要求有返回值,但是,我们在传递了一个空参数,此时 就会产生一个undefined;对于网页的操作时,网页会给我们反馈event对象,所以,当设置监听函数时省略小括号,但是方法本身需要我们传递参数,那么就会传递回去一个event参数
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!