美文网首页
vue3中警告app.config.unwrapInjected

vue3中警告app.config.unwrapInjected

作者: 思我恋 | 来源:发表于2021-09-14 17:14 被阅读0次

[Vue warn]: injected property "formItemEmitter" is a ref and will be auto-unwrapped and no longer needs .value in the next minor release. To opt-in to the new behavior now, set app.config.unwrapInjectedRef = true (this config is temporary and will not be needed in the future.)

父组件通过provide注入一个对象,为了保持响应式,写法如下

provide () {
    return {
        formItemEmitter: computed(() => this.thisEmitter)
    };
},

后代组件通过inject来使用的时候必须要加一层.value,这样使用的时候就会出现上面的警告

当我加上app.config.unwrapInjectedRef = true配置的时候

通过option api形式写的代码不加.value没问题,但是在setup中const formItemEmitter = inject('formItemEmitter');就报错了,断点一看还是有一层value在

无奈只能所有地方都加.value了,就让它警告去吧╮(╯▽╰)╭

相关文章

网友评论

      本文标题:vue3中警告app.config.unwrapInjected

      本文链接:https://www.haomeiwen.com/subject/mrwcgltx.html