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