【发布时间】:2023-12-27 23:45:01
【问题描述】:
在这里,我正在使用 vuetify 设计一个项目,目前我正在研究 vuetify 主题颜色,通过我可以更改导航抽屉、菜单栏和页面的背景颜色,但这样做我发现我再次重复代码并且再次增加了我的代码长度。所以,现在我正试图缩短我的代码。您可以在下面看到我正在重复代码:
颜色:[ { 文本:“蓝色”,值:“#2196F3”}, { 文本:“紫色”,值:“#9C27B0”}, { 文本:“灰色”,值:“#9E9E9E”}, {文本:“粉红色”,值:“#E91E63”}, { 文本:“橙色”,值:“#FF9800”}, { 文本:“蓝绿色”,值:“#009688”}, { 文本:“青色”,值:“#00BCD4”}, { 文本:“琥珀”,值:“#FFC107”}, { 文本:“深紫色”,值:“#673AB7”}, { 文本:“深橙色”,值:“#FF5722”}, { 文本:“绿色”,值:“#4CAF50”} ]
我的代码在这里:
<template>
<v-menu offset-y>
<template v-slot:activator="{ on }">
<v-btn v-on="on" icon height="40" width="40" title="Personal preferences">
<v-icon class="mt-1" size="28">mdi-account-cog</v-icon>
</v-btn>
</template>
<v-list dense>
<v-list-item @click.stop="dialog = true">
<v-list-item-icon class="mr-2">
<v-icon color="red">mdi-select-color</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>
Themes/Colours
</v-list-item-title>
</v-list-item-content>
<v-dialog v-model="dialog" max-width="400">
<v-card>
<v-card-title>Theme</v-card-title>
<v-card-text>
<v-btn
v-for="color in colors"
:key="color.text"
:color="color.text"
@click="changeTheme(color.value)"
class="ma-2"
style="width:150px;"
>{{color.text}}</v-btn>
</v-card-text>
</v-card>
</v-dialog>
</v-list-item>
<v-list-item>
<v-list-item-icon class="mr-2">
<v-icon>mdi-bell-off</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>
Notification Preferences
</v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list>
</v-menu>
</template>
<script>
export default {
data() {
return {
dialog: false,
theme: "",
colors: [
{ text: "blue", value: "#2196F3" },
{ text: "purple", value: "#9C27B0" },
{ text: "grey", value: "#9E9E9E" },
{ text: "pink", value: "#E91E63" },
{ text: "orange", value: "#FF9800" },
{ text: "teal", value: "#009688" },
{ text: "cyan", value: "#00BCD4" },
{ text: "amber", value: "#FFC107" },
{ text: "deep-purple", value: "#673AB7" },
{ text: "deep-orange", value: "#FF5722" },
{ text: "green", value: "#4CAF50" }
]
}
},
methods: {
changeTheme(item) {
this.theme = item;
console.log(item);
this.$vuetify.theme.themes.light.primary = item;
}
}
}
</script>
【问题讨论】:
-
我没有看到重复的代码。你指的是哪几行?
-
@tony19 我的意思是颜色部分......不能把它做成简单的形式吗:colors: ["red","pink","purple","deep-purple ","靛蓝","蓝色","浅蓝色","青色","蓝绿色","绿色","浅绿色","青柠色","黄色","琥珀色","橙色", "深橙色","棕色","蓝灰色","灰色"]
-
这里的主要问题是您无法用简单的语言解释您的主要问题是什么。如果您无法向其他人解释问题,很可能您也不会得到任何有用的回复或解决方案。
标签: vue.js vue-component vuetify.js