解决办法,判断元素有没有点击事件,没有就绑定
if (element.hasAttribute('onclick')) {
console.log('元素有onclick事件');
} else {
console.log('元素没有onclick事件');
element.addEventListener('click', finishEvent);
}
doc.querySelectorAll('.test-item-finish').forEach(function(element) {
let finishEvent = function(event) {
let userId = sessionStorage.getItem("userId");
if (userId == null || userId == "" || userId == "null") {
if (config.configData.loginType == "wx") {
that.showScanLogin = true;
} else {
that.$router.push({
path: '/login',
})
}
return false;
}
let postBody = {dataId: element.dataset.id};
that.$showLoading();
testItemFinish(postBody).then((res) => {
that.$closeLoading();
that.queryClick();
})
}
if (element.hasAttribute('onclick')) {
console.log('元素有onclick事件');
} else {
console.log('元素没有onclick事件');
element.addEventListener('click', finishEvent);
}
});