uniapp里面button类型报错:不能将类型“"primary"”分配给类型“"button"..?
;如图,uniapp里button的类型走的是html的类型,我装了@uni-helper/uni-app-types和volar以后依旧没有解决,请问怎么解决这个问题
回复
1个回答

test
2024-07-12
应该是官方的没有写的锅,去年有人提过一样的问题,官方说已经确认等待开发团队解决,但是没有后续,不知道官方最终修复了没有。
社区有人提供了组件类型声明的仓库 @uni-helper/uni-app-types, 看OP你也安装了,但是不知道你有没有按照这个仓库的说明配置以及调整 Volar
?
配置
tsconfig.json
,确保compilerOptions.types
中含有@dcloudio/types
和@uni-helper/uni-app-types
且include
包含了对应的vue
文件{ "compilerOptions": { "types": ["@dcloudio/types", "@uni-helper/uni-app-types"] }, "vueCompilerOptions": { "experimentalRuntimeMode": "runtime-uni-app", "nativeTags": ["block", "component", "template", "slot"] }, "include": ["src/**/*.vue"] }
安装Volar
之后,建议启用Volar
的Take Over Mode
。如果不想启用Take Over Mode
,可以安装TypeScript Vue Plugin (Volar)
。启用或安装后需要重启VSCode
。
相关阅读uniapp button组件type类型的类型 - DCloud问答types(defineComponent): support for expose component types by pikax · Pull Request #3399 · vuejs/corenativeTags is hard to use · Issue #2165 · johnsoncodehk/volar
回复

适合作为回答的
- 经过验证的有效解决办法
- 自己的经验指引,对解决问题有帮助
- 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
- 询问内容细节或回复楼层
- 与题目无关的内容
- “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容