vue3开发中遇到的问题

786 阅读1分钟

eslint报错:Expected linebreaks to be 'LF' but found 'CRLF'.

解决方案:在.eslintrc.js文件中的rules添加'linebreak-style': ["error", "windows"], // 声明这是windows操作系统。

逗号运算符的左侧未使用,没有任何副作用。

解决方案:对象、数组使用不正确

Property xxx was accessed during render but is not defined on instance

解决方案:vue3 里面碰到的,基本上都是没有return

vite+vue3.0 jsx (tsx) 踩坑报错ReferenceError: React is not defined

解决方案:npm i '@vitejs/plugin-vue-jsx'

image.png

不能将类型“boolean”分配给类型“Ref”。ts(2322) Remove this useless assignment to variable "showPicker".

要使用showPicker.value = false 而不是showPicker = false

v-model:show在tsx中不起作用 .Runtime directive used on component with non-elemen t root node

意思是自定义指令不能放到组件上,而是要放到自有的元素上

模块 ““path““ 只能在使用 “allowSyntheticDefaultImports“ 标志时进行默认导入

请在tsconfig.node.json文件的compilerOptions对象里写上"allowSyntheticDefaultImports": true

TS2769: Property 'xxx' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttribute

原因是Typescript是强类型语言,如果要给组件传值,需要在接受值组的地方声明值类型,就本例而言,需要明确定义`props`

vue3 emit is not a function

defineEmits() is a compiler-hint helper that is only usable inside <script setup> of a single file component. Its arguments should be compiled away and passing it at runtime has no effect.

报错:JSX.Element”的参数不能赋给类型“string | Node”的参数

const rangeEle = <div class="timeRange"> <input class="rangeInput" value="${startTime}"/> - <input class="rangeInput" value="${endTime}"/> </div> let el = document.getElementsByClassName('van-picker__toolbar')[0] el?.insertAdjacentHTML('afterend', rangeEle)