VUEJS项目实践七之Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of

在VueJS项目中,遇到`Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.`错误。该错误发生在尝试移除一个非子节点时。问题源于一个使用了自定义键盘指令`v-key-bind-listen`的MessageBox组件。在按下ESC键关闭和ENTER键确认时,按下ENTER会触发此错误。通过检查发现`destroy`方法被调用了两次,第二次调用时`this.$el`不再为body的子节点。解决方案是在`destroy`方法中添加判断,确保`this.$el`是body的子节点后再进行删除操作,从而解决了问题。
摘要由CSDN通过智能技术生成

问题描述:
Failed to execute ‘removeChild’ on ‘Node’: The node to be removed is not a child of this node.

问题背景:
在我之前的博文
VUEJS项目实践五之Dialog弹出框MessageBox(超好看的bootstrap样式)
中有介绍一个样式结合了Bootstrap样式的MesageBox

然后在之前的博文
VUEJS项目实践四之自定义键盘指令(按键即获取焦点)
中介绍了一种按键自动获取焦点,并触发事件的方法。

现在在MessageBox绑定按键Enter的时候,发现报错
messageBox.vue?cb02:80 Uncaught DOMException: Failed to execute ‘removeChild’ on ‘Node’: The node to be removed is not a child of this node.
在这里插入图片描述

首先贴一下Message.vue文件

<template>
  <div v-key-bind-listen>
      <div class="msgBox" v-show="isShowMessageBox">
        <div class="msgBox_header">
          <div class="msgBox_title">
            <h3>{
   {
    title }}</h3>
          </div>
        </div>

        <div class="msgBox_content">
          <p>{
   {
    content }}</p>
        </div>

        <div class="msgBox_btns">
          <button type="button" class="btn btn-lime btn-lg" id="confirmBtn" @click="confirm"  bind_key="ENTER">确定</button>
          <button type="button" class=
  • 22
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值