【发布时间】:2020-02-25 01:11:55
【问题描述】:
当我将provide/inject 与类组件一起使用时,一切都按预期工作。但是,当我在 “普通”vue 组件中使用它时,我得到 type-errors。
在此示例中,我在引用 this.testService 时遇到错误。代码虽然有效。
export default Vue.extend({
name: "HelloWorldBasic" as string,
inject: ["testService"],
computed: {
message(): string | null {
return this.testService ? this.testService.hello() : null;
}
}
});
我在哪里犯错了?代码应该怎么写?
我建立了一个小项目,以便能够重现并使用它:
$ git clone git@github.com:schnetzi/vue-provide-inject.git
$ npm ci
$ npm start
【问题讨论】:
-
你好,这个有消息吗?
-
到目前为止我没有找到任何解决问题的方法:/
-
你有没有解决它@schnetzi?如果是,怎么做?
标签: vue.js vue-component