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">
<h2>计数器: {
{message}}</h2>
<!-- 普通写法 -->
<button @click="add">+</button>
<!-- 语法糖写法 -->
<button v-on:click="decrement">-</button>
</div>
<script src="../vue.js"></script>
<script>
const app = new Vue({
el:'#app',
data: {
message: 0
},
methods: {
ad