(function () {
window.Message = class Message {
constructor(type, message, timerout) {
this.dom = null;
this.type = type;
this.message = message;
this.timerout = timerout;
}
showMessage() {
let writediv = document.createElement("div");
writediv.setAttribute("class", "wr")
writediv.innerHTML = this.message;
this.dom = writediv;
switch (this.type) {
case "success":
writediv.setAttribute("class", "wr1");
break;
case "waring":
writediv.setAttribute("class", "wr2");
break;
case "error":
writediv.setAttribute("class", "wr3");
break;
}
document.body.append(writediv);
setTimeout(() => {
this.hiddenMessage();
}, this.timerout);
}
hiddenMessage() {
document.body.removeChild(this.dom);
}
}
})()
报错内容:Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.
报错截图:
现在好多组件都有这种提示框,拿过来改改样式就很方便了,为啥还要js封装这种意义不大的东西呢
this.$message({
showClose: true,
type: 'warning',
message: '提示信息'
})
这种更香
The node to be removed is not a child of this node. 应该是移除的时候有问题呢, 第一次执行的时候已经移除了,第二次再移除就有问题了 增加个判断把 如果不为空再移除