vue3中警告app.config.unwrapInjectedRef = true

[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了,就让它警告去吧╮(╯▽╰)╭

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容