【发布时间】:2018-06-25 03:30:57
【问题描述】:
在我的 index.js 文件中,我已经手动用我公司的颜色覆盖了 Vuetify theme 对象:
Vue.use(Vuetify, {
theme: {
primary: '#377ef9',
secondary: '#1b3e70',
accent: '#ff643d',
error: '#ff643d'
...
}
现在,我可以像这样使用模板中的这些颜色:
<my-text-field name="input text"
label="text"
value="text text text text..."
type="text"
color="primary">
</my-text-field>
我所追求的是在我的模板样式中使用primary 或上面定义的theme 对象中的任何其他变量:
<script>
import { VTextField } from 'vuetify'
export default {
extends: VTextField
}
</script>
<style scoped lang="stylus">
label
color: <seconday color> <-- this is what I'm after
color: #1b3e70 <-- this works, but not quite good enough for me
</style>
我可以轻松地将颜色的十六进制值写在样式部分,但我不想重复自己,宁愿使用我的 theme 对象,这样我也更容易轻松更改到处都是颜色,避免拼写错误导致颜色定义错误。
【问题讨论】:
-
不确定,但我相信您也需要在
.styl(即main.styl)中定义它们。或者在例如custom_colors.styl然后在组件中导入<style scoped lang="stylus"> -
@Traxo 我不想定义我的样式两次。维护会越来越难。寻找一个完美的解决方案,我可以在一个地方定义我的东西,并在整个系统中使用它......
-
我明白,这就是我发表评论的原因,因为我不是 100% 确定有 vuetify 解决方案。我相信唯一的 vuetify 方法是将这些值复制到
.styl -
查看我的answer中的重要编辑。
-
我遇到了同样的问题,最终在我的组件中使用了 this.$vuetify.theme.currentTheme.accent
标签: vuejs2 vue-component vuetify.js