定义函数事件的方法

 

<!-- 定义事件的函数方法时,不带参数,函数接收时,可以接收到event
定义事件的函数方法时,带参数$event,函数接收时,可以接收到event -->
<button @click="ctnFun">{{name1}}</button>
<button @click="btnFun($event,9)">{{name2}}</button>
<hr>
<!-- prevent阻止默认事件 -->
<a href="./day02.html" @click.prevent="func">我是一个测试文本的a链接</a>
<hr>
<!-- stop 阻止冒泡事件-->
<div @click="divBtn" style="width: 300px;height:300px;background-color: black;">
<button @click.stop="btn" style="width: 50px;height:50px;background-color:red;">按钮</button>
</div>
<hr>
<!-- once只执行一次事件 -->
<button @click.once="oneBtn">只执行一次的按钮</button>
<hr>
<!-- 键盘抬起触发 enter不区分大小写-->
<!-- <input type="text" @keyup.enter="enterFun"> -->
<input type="text" @keyup.ctrl.c="enterFun">
<div>{{userValue}}</div>
<!-- 键盘按下触发 -->
<!-- <input type="text" @keydown.tab="enterFun"> -->
<!-- <input type="text" @keydown.hc="enterFun"> -->
<!-- 作业:keycode设置空格触发
ctrl+a进行复制 ctrl+b进行粘贴 -->
</div>
</body>
<script src="./js/vue.js"></script>
<script>
Vue.config.productionTip = false;//阻止开发环境提示
Vue.config.keyCodes.hc = 13;//设置键码值的名称
new Vue({
el:"#app",
data:{
name1:"按钮1",
name2:"按钮2",
userValue:"123"
},
methods: {
// 点击事件
ctnFun(evnet){
console.log("被点击了");
// console.log(event);
// console.log(event.target.innerText);
},
// 点击事件
btnFun(a,b){
console.log("被点击了");
console.log(a);
console.log(b);
// console.log(event.target.innerText);
},
// a标签点击事件
func(){
console.log("a被点击了");
},
// div标签点击事件
divBtn(){
console.log("div被触发了");
},
// 按钮标签点击事件
btn(){
console.log("btn被触发了");
},
// 只执行一次的btn点击
oneBtn(){
console.log("触发了一次点击");
},
// 键盘按下事件
enterFun(e){
console.log("键盘按下了");
console.log(e);
console.log(e.target.value);
console.log(this.userValue);
this.userValue = e.target.value;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值