vue/no-src-attribute
不建议在 SFC 块上使用 src 属性。
| 默认严重程度 | 预设 | 自动修复 | 选项 |
|---|---|---|---|
warning |
nuxt, opinionated |
不支持 | 无 |
适用范围:Vue SFC 模板和代码块,包括规则所需的脚本上下文。
错误示例
SFC 块通过 src 文件提供模板、脚本和样式内容。
<template src="./template.html"></template>
<script src="./script.ts"></script>
<style src="./style.css"></style>
正确示例
每个 SFC 块都包含自身内容,不使用外部 src 属性。
<template>
<p>Hello</p>
</template>
<script setup lang="ts">
const label = "Hello";
</script>
<style scoped>
p {
color: red;
}
</style>
配置(Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"vue/no-src-attribute": "warn"
}
},
});
然后运行 vp run lint。