Vue -- 如何在 span 标签上实现一个点击事件
使用 JQuery 时,需要通过下述方式为选中的页面元素绑定单击事件$(".myclass").on("click" , function(){}但在 Vue 中则不必这么麻烦,如果想为某一个 span 标签绑定 click 单击事件,只需<div style="display:flex;position:relative;"><span @click="clickFunc"&g
·
使用 JQuery 时,需要通过下述方式为选中的页面元素绑定单击事件
$(".myclass").on("click" , function(){
}
但在 Vue 中则不必这么麻烦,如果想为某一个 span 标签绑定 click 单击事件,只需
<div style="display:flex;position:relative;">
<span @click="clickFunc">Test</span>
</div>
function init(){
this.template='#testId',
this.data=function () {
return {
}
},
this.methods = {
clickFunc : function(){
console.log(1);
}
},
this.mounted=function(){
}
}
效果:
在单击显示在页面上的 Test 时,F12 控制台会输出 1
更多推荐
已为社区贡献24条内容
所有评论(0)