diff --git a/projects/d5a7f581-c442-4554-87b9-ee723b8b0258/Naive UI 按钮颜色覆盖与 Vue scoped 样式的坑.md b/projects/d5a7f581-c442-4554-87b9-ee723b8b0258/Naive UI 按钮颜色覆盖与 Vue scoped 样式的坑.md new file mode 100644 index 0000000..673c611 --- /dev/null +++ b/projects/d5a7f581-c442-4554-87b9-ee723b8b0258/Naive UI 按钮颜色覆盖与 Vue scoped 样式的坑.md @@ -0,0 +1,31 @@ +--- +title: Naive UI 按钮颜色覆盖与 Vue scoped 样式的坑 +type: experience +permalink: main/projects/d5a7f581-c442-4554-87b9-ee723b8b0258/naive-ui-按钮颜色覆盖与-vue-scoped-样式的坑 +stable_id: d8b18268-4519-41e4-afa5-1e44c8c1e285 +scope: project +memory_type: experience +project_id: d5a7f581-c442-4554-87b9-ee723b8b0258 +usage_profile_id: 0c9feb46-d06e-43cd-9ef0-c5813c84a998 +status: active +revision: 1 +request_id: exp-naive-inline-vars-20261106 +created_at: '2026-11-06T07:36:35.542359+00:00' +updated_at: '2026-11-06T07:36:35.542359+00:00' +tags: +- frontend +- naive-ui +- css +--- + +## 问题 +- Naive UI 的 NButton 把 --n-text-color、--n-height 等 CSS 变量写在元素内联 style 上,样式表里对按钮本身覆盖 --n-* 不生效(应用托管启停按钮配色因此一直没显示)。 +- NButton 的 color 属性会被解析计算 hover 色,传 var(--xxx) 会出错,不能用 CSS 变量。 +- Vue scoped 样式里写 `:global(X) .a :deep(.b)` 会被编译成只剩 `X`(整个选择器被 :global 吞掉),规则落到根元素上。 +- n-data-table 列 render 里用 h() 生成的节点没有 scoped 属性,普通 scoped 类不生效,需要 `.页面根类 :deep(.类名)`、全局类或内联样式。 + +## 做法 +- 自定义外观的操作栏用原生 button + scoped CSS,颜色取 main.css 的主题变量(--primary-color、--danger-color 等,已含日夜间值)。 +- 需要给 Naive 按钮里的图标上色时,直接给图标元素设 color(图标用 currentColor),不要改按钮的 --n-* 变量。 +- 日夜间差异放进 main.css 的 :root / [data-theme="dark"] 变量里,不要在 scoped 里写 :global([data-theme])。 +- 表格中可点击的名称统一用全局类 storage-name-link。 \ No newline at end of file