使用 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
 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐