css/prefer-slotted
建议使用 ::v-slotted() 为插槽内容设置样式。
| 默认严重程度 | 预设 | 自动修复 | 选项 |
|---|---|---|---|
warning |
opinionated, nuxt |
不支持 | 无 |
适用范围:CSS、SCSS、Sass、Less 和 Stylus 的 style 块,按原样读取(不运行预处理器)。同一个 Stylus 块内请统一使用花括号语法或缩进语法;混合语法会按花括号 Stylus 读取。
错误示例
scoped 样式表选择的是 slot 出口,而不是通过插槽传入的元素。
<style scoped>
slot { color: red; }
</style>
正确示例
:slotted(.label) 通过作用域插槽选择器选中传入的 label 元素。
<style scoped>
:slotted(.label) { color: red; }
</style>
配置(Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"css/prefer-slotted": "warn"
}
},
});
然后运行 vp run lint。