【问题标题】:Uncaught (in promise) TypeError: Cannot read properties of null (reading 'insertBefore')Uncaught (in promise) TypeError: Cannot read properties of null (reading 'insertBefore')
【发布时间】:2021-12-12 12:59:34
【问题描述】:
<div class="button" @click="shows = !show">
  <i class="fas fa-plus-circle" v-if="show"></i>
  <i class="fas fa-minus-circle" v-else></i>
</div>

如果我单击该元素,它会显示错误“Uncaught (in promise) TypeError: Cannot read properties of null (reading 'insertBefore')”。

不知道为什么,但在附加了事件处理程序的元素内渲染元素时似乎存在问题。

【问题讨论】:

    标签: vue.js


    【解决方案1】:

    此@click="shows = !show" 代码不正确。你应该在methods 部分声明一个函数:

    methods: {
     onClick() {
       this.show = !this.show;
     }
    }
    

    然后使用它:

    @click="onClick"
    

    另外,也许这是一个错字? show**s** = !show

    【讨论】:

    • 想通了。在 vue js 中的 Fontawesome 中使用 dom.watch(),因此它将 转换为 。只需用
      封装 并在
      上添加 v-if 和 v-else。现在它的工作。
    猜你喜欢
    • 2021-12-21
    • 1970-01-01
    • 2022-07-01
    • 2022-01-11
    • 2021-11-10
    • 2022-01-11
    • 1970-01-01
    • 2022-10-09
    • 2022-07-21
    相关资源
    最近更新 更多