vue/no-template-target-blank
禁止使用 target="_blank" 而不设置 rel="noopener noreferrer"。
| 默认严重程度 | 预设 | 自动修复 | 选项 |
|---|---|---|---|
warning |
happy-path, nuxt, ecosystem, opinionated |
不支持 | 无 |
适用范围:Vue SFC 模板和代码块,包括规则所需的脚本上下文。
错误示例
外部链接打开新的浏览上下文,却没有预期的 rel 保护。
<template>
<a href="https://example.com" target="_blank">x</a>
</template>
正确示例
同一链接在 target=_blank 之外还包含 noopener noreferrer。
<template>
<a href="https://example.com" target="_blank" rel="noopener noreferrer">x</a>
</template>
配置(Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"vue/no-template-target-blank": "warn"
}
},
});
然后运行 vp run lint。