vue/no-useless-mustaches
禁止表达式为常量字符串字面量的双花括号插值。
| 默认严重程度 | 预设 | 自动修复 | 选项 |
|---|---|---|---|
warning |
nuxt, opinionated |
不支持 | 无 |
适用范围:Vue SFC 模板和代码块,包括规则所需的脚本上下文。
错误示例
插值仅包含常量字符串,无需对表达式求值。
<template>
<div>{{ 'x' }}</div>
<div>{{ "x" }}</div>
<div>{{ `x` }}</div>
</template>
正确示例
字面文本直接写入模板;变量表达式、带插值的模板字符串,以及有意作为分隔符的空白,仍可使用插值。
<template>
<div>x</div>
<div>{{ x }}</div>
<div>{{ `pre-${x}` }}</div>
<span>A</span> {{ " " }} <span>B</span>
</template>
配置(Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"vue/no-useless-mustaches": "warn"
}
},
});
然后运行 vp run lint。