[英]How to configure ESLint to understand Vue.js v-model directive?
Let's have a sample single file Component:让我们有一个示例单文件组件:
<template>
<InputComponent v-model="foo" />
</template>
<script setup>
let foo = 1
</script>
ESLint says: ESLint: 'foo' is never reassigned. Use 'const' instead. (prefer-const)
ESLint 说:
ESLint: 'foo' is never reassigned. Use 'const' instead. (prefer-const)
ESLint: 'foo' is never reassigned. Use 'const' instead. (prefer-const)
However since it is used in a v-model directive it is used in a read-write context, it should be okay.但是,由于它在 v-model 指令中使用,它在读写上下文中使用,应该没问题。
I have installed eslint-plugin-vue
and has the parser set to vue-eslint-parser
in my .eslintrc.
我已经安装了
eslint-plugin-vue
并在我的 .eslintrc 中将解析器设置为vue-eslint-parser
.eslintrc.
but somehow it does not seem to understand what is going on with the v-model
directive.但不知何故,它似乎不明白
v-model
指令发生了什么。
How to configure ESLint to understand Vue.js v-model directive?如何配置 ESLint 以理解 Vue.js v-model 指令?
Based on Vue documentation actually a const should be used, because primitive types should be declared by the ref()
helper which returns a proxy which in turn will not be reassigned.根据 Vue 文档,实际上应该使用 const,因为原始类型应该由
ref()
助手声明,该助手返回一个代理,而该代理又不会被重新分配。 So probably the proper code is like this:所以可能正确的代码是这样的:
<template>
<InputComponent v-model="foo" />
</template>
<script setup>
import { ref } from 'vue'
const foo = ref(1)
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.