ElementPlusError: [ElOnlyChild] no valid child node found

记录一起使用Element Plus时出现的错误,错误信息如下:

ElementPlusError: [ElOnlyChild] no valid child node found
    at debugWarn (error.ts:13:37)
    at Proxy.<anonymous> (only-child.tsx:39:11)
    at renderComponentRoot (runtime-core.esm-bundler.js:834:16)
    at ReactiveEffect.componentUpdateFn [as fn] (runtime-core.esm-bundler.js:5852:26)
    at ReactiveEffect.run (reactivity.esm-bundler.js:178:19)
    at instance.update (runtime-core.esm-bundler.js:5902:51)
    at updateComponent (runtime-core.esm-bundler.js:5729:18)
    at processComponent (runtime-core.esm-bundler.js:5664:7)
    at patch (runtime-core.esm-bundler.js:5128:11)
    at ReactiveEffect.componentUpdateFn [as fn] (runtime-core.esm-bundler.js:5861:9)

而且也没法定位到具体是哪行代码报的错,只能一行行的逐渐排查,终于定位到如下的代码:

  <el-button-group >
    <el-tooltip content="编辑" placement="bottom">
      <el-button v-if="c.categoryId" size="small" :icon="EditPen" @click="onShowUpdateDialog(c)"></el-button>
    </el-tooltip>
    <el-tooltip content="移除" placement="bottom">
      <el-button v-if="c.categoryId" size="small" :icon="Close" @click="onRemove(c)"></el-button>
    </el-tooltip>
  </el-button-group>

出现这种错误的原因是el-tooltip的子元素用到了v-if,有可能造成子元素为空,所以正确的解决办法是把v-if放在el-tooltip或el-tooltip的父元素上,修正后的代码如下:

  <el-button-group v-if="c.categoryId">
    <el-tooltip content="编辑" placement="bottom">
      <el-button size="small" :icon="EditPen" @click="onShowUpdateDialog(c)"></el-button>
    </el-tooltip>
    <el-tooltip content="移除" placement="bottom">
      <el-button size="small" :icon="Close" @click="onRemove(c)"></el-button>
    </el-tooltip>
  </el-button-group>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Greentea107

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值