vue3+ts项目中eslint问题记录

594 阅读1分钟

Component name "Tabs" should always be multi-word vue/multi-word-component-names

配置.eslintrc.json中的rules:

"vue/multi-word-component-names": ["off"]

error '.native' modifier on 'v-on' directive is deprecated vue/no-deprecated-v-on-native-modifier

'.native'修饰符在vue3中被弃用了,所以在代码中去掉.native就可以了。

error Custom elements in iteration require 'v-bind:key' directives vue/valid-v-for

原因是代码模板中使用了v-for, 但是没有绑定key值,解决办法建议给v-for绑定key值。

Unexpected mutation of "isShowDialog" prop vue/no-mutating-props

父组件传递过来的变量绑定弹窗会报错,原因是单向数据流,子组件不能该变父组件变量。

改成如下写法:

//父组件
<biz-detail
    v-model:isShowDialog="state.isShowDialog"
    ...
></biz-detail>
//子组件
...
<el-dialog
    v-model="dialogVisible"
    ...
>...</dialog>

const emits = defineEmits(['update:isShowDialog'])
const dialogVisible = computed({
  get: () => props.isShowDialog,
  set: (val: boolean) => {
    emits('update:isShowDialog', val)
  }
})