【发布时间】:2021-04-19 08:26:21
【问题描述】:
我使用了新的 Vue 3 组合 API,并为响应式数据编写了一个“存储”。
const state = reactive<State>({
accessToken: undefined,
user: undefined,
});
export default {
state: readonly(state),
}
在创建应用时,我将商店提供给所有组件:
const app = createApp(App)
.provide("store", store)
.use(IonicVue)
.use(router);
最后在一个组件/视图中,我注入 store 以使用它。
export default defineComponent({
name: "Home",
inject: ["store"],
components: {
IonContent,
IonHeader,
IonPage,
IonTitle,
IonToolbar,
IonButton,
},
computed: {
email() {
return this.store.state.user.email;
},
},
});
</script>
不幸的是,Typescript 不喜欢我在 computed 属性 email() 中使用 this.store 的方式@
然后说
类型“ComponentPublicInstance>'
我的意思是当我删除<script/> 标记中的lang="ts" 时一切正常,但没有显示错误。
关于如何解决这个问题或它的特别含义有什么建议吗?
提前致谢!
【问题讨论】:
标签: typescript vue.js vuejs3