vue如何動態(tài)設(shè)置背景漸變色
更新時間:2024年08月28日 11:07:42 作者:迪爾~
這篇文章主要介紹了vue如何動態(tài)設(shè)置背景漸變色問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
vue動態(tài)設(shè)置背景漸變色
效果展示

核心(動態(tài)更換單一的背景顏色也可以使用)

<div class="ss" v-bind:style="{ background: colors }"></div>
//漸變色顏色代碼
// background:linear-gradient(90deg,#0af,#0085ff);代碼
<template>
<div>
<el-row :gutter="20">
<!-- 兩邊左側(cè)邊框空位 無用 -->
<el-col :span="4"><div class="frame"></div></el-col>
<!-- 中間左側(cè)邊框背景顏色選擇器 主要代碼 -->
<el-col :span="8">
<div class="middle">
<ul class="middle-ul">
<li class="middle-li">
背景顏色1:
<el-color-picker
size="mini"
v-model="colors1"
show-alpha
color-format=" hsv "
:predefine="predefineColors"
@change="firstChangeColor"
>
</el-color-picker>
</li>
<li class="middle-li">
背景顏色2:
<el-color-picker
size="mini"
v-model="colors2"
show-alpha
color-format=" hsv "
:predefine="predefineColors"
@change="secondChangeColor"
>
</el-color-picker>
</li>
</ul>
</div>
</el-col>
<!-- 中間右側(cè)邊框效果展示區(qū) 主要代碼 -->
<el-col :span="8">
<div class="middle">
<div class="ss" v-bind:style="{ background: colors }">
<ul class="middle-ul">
效果展示
</ul>
</div>
</div>
</el-col>
<!-- 兩邊右側(cè)邊框空位 無用 -->
<el-col :span="4"><div class="frame"></div></el-col>
</el-row>
</div>
</template><script>
export default {
data() {
return {
// <--主要代碼
colors1: "",
colors2: "",
colors: "",
// 主要代碼-->
predefineColors: [
"#ff4500",
"#ff8c00",
"#ffd700",
"#90ee90",
"#00ced1",
"#1e90ff",
"#c71585",
"#c7158577",
],
};
},
// <--主要代碼
methods: {
firstChangeColor(val) {
this.colors1 = val;
if (Object.keys(this.colors2).length == 0) {
this.$message({
message: "請選擇顏色2",
type: "warning",
});
} else {
this.colors = "linear-gradient(90deg," + this.colors1 + "," + this.colors2 + ")";
}
},
secondChangeColor(val) {
this.colors2 = val;
if (Object.keys(this.colors1).length == 0) {
this.$message({
message: "請選擇顏色1",
type: "warning",
});
} else {
this.colors = "linear-gradient(90deg," + this.colors1 + "," + this.colors2 + ")";
}
},
},
// 主要代碼-->
};
</script><style>
.el-row {
margin-bottom: 20px;
}
.el-col {
border-radius: 4px;
}
.middle {
border-radius: 4px;
min-height: 250px;
background: #fdfdfd;
}
.frame {
border-radius: 4px;
min-height: 250px;
background: #f0f2f5;
}
.ss {
float: left;
margin-top: 25px;
margin-left: 100px;
width: 300px;
height: 200px;
border-radius: 19px;
}
.middle-ul {
margin: 0;
padding: 0;
list-style: none;
}
.middle-li {
margin-left: 25px;
list-style: none;
line-height: 40px;
}
</style>總結(jié)
以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue+element-ui表格封裝tag標(biāo)簽使用插槽
這篇文章主要介紹了vue+element-ui表格封裝tag標(biāo)簽使用插槽,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06
Vue項(xiàng)目通過vue-i18n實(shí)現(xiàn)國際化方案(推薦)
這篇文章主要介紹了Vue項(xiàng)目通過vue-i18n實(shí)現(xiàn)國際化方案,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-12-12
vue調(diào)用swiper插件步驟教程(最易理解且詳細(xì))
有時候我們需要在vue中使用輪播組件,如果是在vue組件中引入第三方組件的話,最好通過npm安裝,從而進(jìn)行統(tǒng)一安裝包管理,下面這篇文章主要給大家介紹了關(guān)于vue調(diào)用swiper插件的相關(guān)資料,需要的朋友可以參考下2023-04-04
vue使用自定義事件的表單輸入組件用法詳解【日期組件與貨幣組件】
這篇文章主要介紹了vue使用自定義事件的表單輸入組件用法,結(jié)合實(shí)例形式詳細(xì)分析了vue.js日期組件與貨幣組件相關(guān)操作技巧及注意事項(xiàng),需要的朋友可以參考下2020-06-06
element-ui中el-form-item內(nèi)的el-select該如何自適應(yīng)寬度
自從用了element-ui,確實(shí)好用,該有的組件都有,但是組件間的樣式都固定好了,下面這篇文章主要給大家介紹了關(guān)于element-ui中el-form-item內(nèi)的el-select該如何自適應(yīng)寬度的相關(guān)資料,需要的朋友可以參考下2022-11-11
關(guān)于Vue?監(jiān)控數(shù)組的問題
這篇文章主要介紹了Vue?監(jiān)控數(shù)組的示例,主要包括Vue?是如何追蹤數(shù)據(jù)發(fā)生變化,Vue?如何更新數(shù)組以及為什么有些數(shù)組的數(shù)據(jù)變更不能被?Vue?監(jiān)測到,對vue監(jiān)控數(shù)組知識是面試比較常見的問題,感興趣的朋友一起看看吧2022-05-05
webpack + vue 打包生成公共配置文件(域名) 方便動態(tài)修改
這篇文章主要介紹了webpack + vue 打包生成公共配置文件(域名) 方便動態(tài)修改,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2019-08-08

