文章目录
1. 在vue3加ts的项目中编辑器总是报 vue模块找不到
,以及使用组合式API的时候报非类型化函数调用不能接受类型参数
等错误
解决方法:
1. 在tsconfig.json 文件中 将 `moduleResolution` 配置项的值改为`Node`
2. vue3 怎么将一段带有html结构的字符串渲染到页面上?
解决方法:
使用v-html指令
如:
<p v-html="你好<br/>世界"></p>
3. Vue3中怎么使用JSX或者TSX?
解决方法(仅在vite脚手架中,webpack还未遇到):
下载插件
pnpm i @vitejs/plugin-vue-jsx -D
并在vite.config.ts中做配置:
import vueJsx from '@vitejs/plugin-vue-jsx'
export default defineConfig({
plugins: [/*其它插件*/, vueJsx()],
// ...
})
4. 在TS中怎么为下载的插件属性中添加一个属性?
由于TS是一门类型严谨的语言,如果该类型声明文件中没有声明后添加的属性,那么编译器就会一直报错,对此我的解决方法就是直接改它的类型声明文件,然后重启编辑器
如图,简单粗暴:
但是这种方法不建议在团队协作开发的项目中使用,大家如果有更好的办法,可以在评论区留言
5. webStorm编辑器报“无法解析符号 ‘xxx’ ”的错误
这种情况右击node_modules文件夹,有一个将目标标记为(Mark Directory as)的选项,我们选择不排除(Not Excluded),等它检索完毕即可解决,期间会提示你要启动npm下载什么东西通通忽略。