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

Logo

前往低代码交流专区

更多推荐