Vue 指令之v-on的使用
2024-08-27
24
v-on 指令用于监听 DOM 事件
1. v-on 基本使用
<div id="app">
<button v-on:click="test">测试</button>
</div>
<script>
let vm = new Vue({
el: '#app',
methods: {
test: function() {
console.log(123)
},
}
})
</script>
v-on
可缩写为 @
<button v-on:click="test">测试</button>
<button @click="test">测试</button>
2. 修饰符
<div id="app">
<span v-on:click="go2('222')">
<!-- .stop 阻止冒泡 -->
<span v-on:click.stop="go('111')">点我</span>
</span>
<br>
<!-- 只有第一次点击会触发函数 -->
<span v-on:click.once="go(333)">只触发一次</span>
</div>
方法中的 this
自动绑定为当前 Vue实例
更新于:20天前<script>
let vm = new Vue({
el: '#app',
methods: {
test: function() {
console.log(123)
},
go: function(msg) {
console.log(msg, this)
},
go2: function(msg) {
console.log(msg, this)
},
}
})
</script>
赞一波!3
相关文章
- TP6.0命令行之自定义指令
- 基于Vue的免费开源admin管理后台框架
- vue cli 项目启动 HBuilderX 编辑器的使用
- vue cli 中的 import 和 export
- Vue cli4 图片地址引入的几种方式
- vue跳转页面的方法
- Vue CLI 脚手架简介及安装
- Vue 创建项目及目录介绍
- Vue组件插槽的使用
- Vue组件之动态组件
- Vue 组件介绍及使用
- Vue 父子组件通信传值(子组件中使用父组件中的数据)
- Vue指令之列表渲染
- Vue指令之条件渲染
- Vue和React怎么选?
- Vue 指令之v-bind指令绑定属性
- Vue 实例、el、data
- Vue 指令之插值 v-text、v-html、v-once
- 2023年最受欢迎的Vue.js UI组件库
- Vue中使用Mock.js模拟接口请求数据
文章评论
全部评论