小编Sam*_*man的帖子

使用 vue.js 在子组件中调用父方法

大家好,我只是想知道如何从子组件调用 perent 函数我尝试使用 $parent 来调用 perent 方法,但我有这个错误 typeError: _this.$parent.forceRender 不是一个函数,这里是父级我试图调用的方法

methods: {
      forceRender() {
        this.componentKey += 1
      }
    },
Run Code Online (Sandbox Code Playgroud)

这是子组件,您可以看到我正在尝试使用 $parent 调用父方法

this.$parent.forceRender()
Run Code Online (Sandbox Code Playgroud)

methods components parent parent-child vue.js

5
推荐指数
2
解决办法
5477
查看次数

标签 统计

components ×1

methods ×1

parent ×1

parent-child ×1

vue.js ×1