【发布时间】:2020-07-28 10:15:18
【问题描述】:
短版:在我的应用程序的data() 中,我定义了某些颜色。我希望html-element 的背景为这些颜色之一,基于switch 声明。
加长版:
在data() 中,我有以下代码:
data() {
return {
item: {},
color1: '',
color2: '',
};
},
在我的 created() 函数中,我从后端获取项目。此外,我编写了以下代码来评估 html-section 的颜色:
switch (this.item.itemType) {
case 'car': this.color1 = '#39ac39'; this.color2 = '#00ff00'; break;
case 'bus': this.color1 = '#3333ff'; this.color2 = '#1a75ff'; break;
case 'plane': this.color1 = '#ff66cc'; this.color2 = '#ffb3e6'; break;
default: this.color1 = '#'; this.color2 = '#';
}
在我的style 部分,我想为整个应用程序的背景设置样式 (html-tag),样式如下:
<style>
html {
background-color: linear-gradient(to bottom, color1, color2);
}
</style>
Vue 可以做到这一点吗?
【问题讨论】:
标签: javascript css vue.js vuejs2 vue-component