/* 主题颜色 */
$color-primary-green:green;
/* 更换的颜色 */
$color-primary-blue:blue;
/* 更换的颜色 */
$data-defalut:"green"

@mixin color_primary() {
    &[data-txt="green"] {
        background: $color-primary-green;
    }

    &[data-txt="blue"] {
        background: $color-primary-blue;
    }

}

.price {
    height: 400px;

    /*color: $color-primary;*/
    /* 原始引用方式,错误 */
    &::before {
        content: attr(data-txt);
    }

    @include color_primary();
    /* 采用函数调用 */
}

 <div class="head price" :data-txt="bgColor" @click="changeSkin">

<script lang="ts">
    import { Vue, Component, Prop, Watch, Emit } from 'vue-property-decorator'
    import { mixins } from 'vue-class-component'
    
bgColor: string = "blue";
 private changeSkin() {
            //this.$refs.bgDom.attributes('data-txt', 'green');
            this.bgColor = this.bgColor == "blue" ? "green" : "blue";
        }
        

参考地址

git 项目地址。详细讲解


木子喵
492 声望26 粉丝

too young, too naive