当前位置:网站首页>07_事件的基本使用
07_事件的基本使用
2022-07-17 00:06:00 【id不存在。】
事件的基本使用
事件的基本使用:
1.使用v-on:xxx或@xxx绑定事件,其中xxx是事件名
2.事件的回调需要配置在methods对象中,最终会在vm上
3.methods中配置的函数,不要用箭头函数,否则this就不是vm了
4.methods中配置的函数,都是被vue所管理的函数,this的指向是vm或组件实例对象
[email protected]="demo"和@click="demo($event)"效果一致,但后者可以传参
<body>
<div id="root">
<h2>欢迎来到{
{name}}学习</h2>
<!-- <button v-on:click="showInfo">点我提示信息</button> -->
<button @click="showInfo1">点我提示信息1(不传参)</button>
<button @click="showInfo2($event,66)">点我提示信息2(传参)</button>
</div>
</body>
<script type="text/javascript">
Vue.config.productionTip = false //阻止 vue 在启动时生成生产提示。
const vm = new Vue({
el: '#root',
data: {
name: '尚硅谷',
},
methods: {
showInfo1(event) {
// console.log(event.target.innerText)
// console.log(this) //此处的this是vm
alert('同学你好!')
},
showInfo2(event, number) {
console.log(event, number)
// console.log(event.target.innerText)
// console.log(this) //此处的this是vm
alert('同学你好!!')
}
}
})
</script>边栏推荐
- C Programming Language (2nd Edition)--读书笔记--1.3
- TCP与UDP,TCP服务器与客户端,UDP服务器与客户端
- 页面布局——三栏布局解决方式
- (四)运算符
- (九)Shell 输入输出重定向
- object-fit:cover;在小程序中不起作用,小程序图片变形了如何处理
- (六)test命令
- JS intercepts the first few digits of the string or the last few digits of the string
- XXX packages are looking for funding run `npm fund` for details解决方法
- 二分法查找
猜你喜欢

VsCode建立非工程目录下的头文件自动查找

Summary of XML external entity injection (xxE target recurrence)

数据库连接池、sequelize实现增删改查等操作

js替换字符串某个字符,js修改字符串中指定字符

Node的数据库编程(MySQL),增删改查

Collection and summary of penetration test information

Redis简单使用

Cve-2022-34265 Django extract & TRUNC SQL injection vulnerability recurrence

量化行业知识汇总

Day06 ORM field and operation
随机推荐
Initial flask
C Programming Language (2nd Edition)--读书笔记--1.5.2
量化行业知识汇总
Fundamentals of IOT development
二分法查找
自己封装的风格化的开关卡片组件
openGauss内核分析-统计信息与行数估计
js截取字符串前几位或者截取字符串后几位
数组操作——判断、去重、合并、展开
(10)文件包含
JS get the suffix format of a file name
js替换字符串某个字符,js修改字符串中指定字符
时间戳转化时间
JS string to object JS object to string JS string to object
页面布局——三栏布局解决方式
Text indent in uniapp doesn't work, and the indentation in the first line of uniapp doesn't work. How to solve it?
Stack injection [strong net cup 2019] random note
Single page application spa and multi page application MPa
C Programming Language (2nd Edition)--读书笔记--1.5.3
ModelArts-图像分类and物体检测