Vue 3 打字稿构建'this is undefined'



我对Vue相当陌生,我使用Vite和TypeScript来制作我的项目。每当我去构建时,我都会得到一页错误,主要由模板部分的Object is possibly 'undefined'组成,例如:

<input :value="this.$store.state.shareUrl"/>

忽略类型检查并查看构建页面会产生一个空白页面,其中包含错误TypeError: Cannot read properties of undefined (reading '$store'),但是该页面在开发版本中完全正常工作。有什么关于如何修复的想法吗?

在Vue模板中,this是隐式的(这就是为什么console.log不能从模板中工作),所以您可以跳过

<input :value="$store.state.shareUrl"/>

相关内容

最新更新