Appearance
vue/no-lone-template
禁止不必要的
<template>
- ⚙️ 此规则包含在
"plugin:vue/recommended"、*.configs["flat/recommended"]、"plugin:vue/vue2-recommended"和*.configs["flat/vue2-recommended"]中。
📖 规则详情
此规则旨在消除不必要的和可能令人困惑的 <template>。在 Vue.js 2.x 中,没有特定指令的 <template> 元素无效。在 Vue.js 3.x 中,没有特定指令的 <template> 元素会按原样渲染 <template> 元素,但在大多数情况下这可能不是你想要的。
¥This rule aims to eliminate unnecessary and potentially confusing <template>.\ In Vue.js 2.x, the <template> elements that have no specific directives have no effect.\ In Vue.js 3.x, the <template> elements that have no specific directives render the <template> elements as is, but in most cases this may not be what you intended.
🔧选项
¥🔧 Options
json
{
"vue/no-lone-template": ["error", {
"ignoreAccessible": false
}]
}ignoreAccessible...如果是true,则忽略可访问的<template>元素。默认false。注意:如果你使用的是 Vue.js 2.x,则此选项无用。¥
ignoreAccessible... Iftrue, ignore accessible<template>elements. defaultfalse.\ Note: this option is useless if you are using Vue.js 2.x.
"ignoreAccessible": true
🔇何时不使用
¥🔇 When Not To Use It
如果你使用的是 Vue.js 3.x 并想有意定义 <template> 元素,则必须关闭此规则或使用 "ignoreAccessible" 选项。
¥If you are using Vue.js 3.x and want to define the <template> element intentionally, you will have to turn this rule off or use "ignoreAccessible" option.
👫相关规则
¥👫 Related Rules
🚀版本
¥🚀 Version
此规则在 eslint-plugin-vue v7.0.0 中引入
¥This rule was introduced in eslint-plugin-vue v7.0.0
🔍代码实现
¥🔍 Implementation