在网站中存在很多按钮,点击会触发不同的功能
那么在 vue
中怎么实现这一功能呢,使用到了 vue
中的 v-on
监听 DOM
事件
例如监听点击 v-on:click = "methodName"
或者使用 语法糖
简写成 @click = "methodName"
-
我们编写一个计数器,更好的理解监听事件。
在
App.vue
中,我们编写如下代码<template> <div id="App"> <div>当前计数:{ { counter }}</div> <button>+1</button> <button>-1</button> </div> </template> <script> export default { name: 'App', data(</