Appearance
vue/no-bare-strings-in-template
禁止在
<template>
中使用裸字符串¥disallow the use of bare strings in
<template>
📖 规则详情
此规则禁止在 <template>
中使用裸字符串。为了能够使你的应用国际化,你需要避免在模板中使用纯字符串。相反,你需要使用专门用于翻译的模板助手。
¥This rule disallows the use of bare strings in <template>
.\ In order to be able to internationalize your application, you will need to avoid using plain strings in your templates. Instead, you would need to use a template helper specializing in translation.
此规则的灵感来自 ember-template-lint 中的无裸字符串规则。
¥This rule was inspired by no-bare-strings rule in ember-template-lint.
Now loading...
提示
此规则不检查字符串字面量、绑定和胡须插值。这是因为它看起来像是一个有意识的决定。如果你想报告这些字符串字面量,请启用 vue/no-useless-v-bind 和 vue/no-useless-mustaches 规则并修复无用的字符串字面量。
¥This rule does not check for string literals, in bindings and mustaches interpolation. This is because it looks like a conscious decision.\ If you want to report these string literals, enable the vue/no-useless-v-bind and vue/no-useless-mustaches rules and fix the useless string literals.
🔧选项
¥🔧 Options
js
{
"vue/no-bare-strings-in-template": ["error", {
"allowlist": [
"(", ")", ",", ".", "&", "+", "-", "=", "*", "/", "#", "%", "!", "?", ":", "[", "]", "{", "}", "<", ">", "\u00b7", "\u2022", "\u2010", "\u2013", "\u2014", "\u2212", "|"
],
"attributes": {
"/.+/": ["title", "aria-label", "aria-placeholder", "aria-roledescription", "aria-valuetext"],
"input": ["placeholder"],
"img": ["alt"]
},
"directives": ["v-text"]
}]
}
allowlist
...允许的字符串数组。¥
allowlist
... An array of allowed strings.attributes
...一个对象,其键是标签名称或模式,值是用于检查该标签名称的属性数组。¥
attributes
... An object whose keys are tag name or patterns and value is an array of attributes to check for that tag name.directives
...用于检查字面量值的指令名称数组。¥
directives
... An array of directive names to check literal value.
👫相关规则
¥👫 Related Rules
🚀版本
¥🚀 Version
此规则在 eslint-plugin-vue v7.0.0 中引入
¥This rule was introduced in eslint-plugin-vue v7.0.0
🔍代码实现
¥🔍 Implementation