切换背景色–sass
// test.sass
$bmg1:red;
$bmg2:black;
$bmg3:green;
$bmg4:purple;
@mixins changes($color){
background:$color;
[data-theme='backgroundcolor1']&{
background:$bmg1;
}
[data-theme='backgroundcolor2']&{
background:$bmg2;
}
[data-theme='backgroundcolor3']&{
background:$bmg3;
}
[data-theme='backgroundcolor4']&{
background:$bmg4;
}
}
//test.vue
<el-button type="primary" @click="changebackground">点击1</el-button>
<el-button type="primary" @click="changebackground2">点击2</el-button>
<el-button type="primary" @click="changebackground3">点击3</el-button>
<el-button type="primary" @click="changebackground4">点击4</el-button>
changebackground(){
window.document.documentElement.setAttribute('data-theme','backgroundcolor1');
}
changebackground2(){
window.document.documentElement.setAttribute('data-theme','backgroundcolor2');
}
changebackground3(){
window.document.documentElement.setAttribute('data-theme','backgroundcolor3');
}
changebackground4(){
window.document.documentElement.setAttribute('data-theme','backgroundcolor4');
}
@import '../http/test.scss';
.box{
@include changes($bmg1);
}