vue/sfc-element-order
要求 SFC 顶层元素保持一致的顺序。
| 默认严重程度 | 预设 | 自动修复 | 选项 |
|---|---|---|---|
warning |
happy-path, nuxt, ecosystem, opinionated |
不支持 | 规则选项 |
适用范围:Vue SFC 模板和代码块,包括规则所需的脚本上下文。
错误示例
style 块位于 script 块之前,不符合配置的 SFC 块顺序。
<style scoped>
.panel {
color: red;
}
</style>
<script setup lang="ts">
const label = "Save";
</script>
正确示例
各块按照 script → template → style 排列。项目可通过此规则的类型化选项选择其他顺序。
<script setup lang="ts">
const label = "Save";
</script>
<template>
<p>{{ label }}</p>
</template>
<style scoped>
p {
color: red;
}
</style>
配置(Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"vue/sfc-element-order": "warn"
}
},
});
然后运行 vp run lint。