Vue3 + Vite + Ts 报错:Property ‘ ‘ does not exist on type ‘never‘

报错代码显示:

src/views/Classfy/index.vue:13:20 - error TS2339: Property 'name' does not exist on type 'never'.

13         

{{ item.name }}

~~~~ src/views/Classfy/index.vue:14:32 - error TS2339: Property 'icon' does not exist on type 'never'. 14 ~~~~ src/views/Home/index.vue:18:20 - error TS2339: Property 'name' does not exist on type 'never'. 18 :key="item.name" ~~~~ src/views/Classfy/index.vue:22:34 - error TS2339: Property 'tagId' does not exist on type 'never'. 22 @click="searchByTag(item.tagId)" ~~~~~ src/views/Home/index.vue:19:32 - error TS2339: Property 'tagId' does not exist on type 'never'. 19 @click="toClassFy(item.tagId)" ~~~~~ src/views/Home/index.vue:21:32 - error TS2339: Property 'icon' does not exist on type 'never'. 21 ~~~~ src/views/Classfy/index.vue:25:20 - error TS2339: Property 'name' does not exist on type 'never'. 25

{{ item.name }}

~~~~ src/views/Home/index.vue:22:41 - error TS2339: Property 'name' does not exist on type 'never'. 22

{{ item.name.slice(0, 1) }}

~~~~ src/views/Home/index.vue:30:20 - error TS2339: Property 'name' does not exist on type 'never'. 30 :key="item.name + 'ss'" ~~~~ src/views/Home/index.vue:32:25 - error TS2339: Property 'cover' does not exist on type 'never'. 32

出现情景:本地开发

修改方法:

所有使用到属性的地方都使用  a['b'] 的形式代替 a.b 来显示数据:

    

{{ item["name"] }}

出现情景:打包

​​​​​​​将 package.json 文件中的  "build": "vue-tsc --noEmit && vite build", 

改为 :   "build": "vite build",

然后重新打包就行 

你可能感兴趣的:(Vue3.0,Vue3,typescript,vite)