Mouted and updated are used in Vue, but the defined $refs is still not available.

clipboard.png

$refsrefs.con

clipboard.png

clipboard.png

I want to do the effect of clicking different buttons in VUE to show different background images
you don"t have to manipulate DOM
, but I don"t know how to get the properties of the parent class in the click event of the subclass and modify
or there are other ways to do this
Thank you guys

.
Mar.03,2021

within the vue file

<div :class="{classFlag ? 'red' : 'blue'}" @click="changeClass">

within the js file

changeClass () {
    this.classFlag = !this.classFlag
}

within the scss file

div {
    &.blue {
        background: blue;
    }
    &.red {
        background: red;
    }
}
< hr >

or you can do this by binding style

< hr >

five backgrounds

within the vue file

<div :class="showClass">
<button @click="changeClass(1)"></button>
<button @click="changeClass(2)"></button>
<button @click="changeClass(3)"></button>
<button @click="changeClass(4)"></button>
<button @click="changeClass(5)"></button>

within the js file

changeClass (i) {
    this.classFlag = i
}
showClass (i) {
    switch (this.classFlag) {
        case 1:
            return 'one'
        case 2:
            return 'two'
        case 3:
            return 'three'
        case 4:
            return 'four'
        case 5:
            return 'five'
        default:
            break
    }
}

within the scss file

div {
    &.one{
        background: blue;
    }
    &.two {
        background: red;
    }
    &.three {
        background: white;
    }
    &.four{
        background: black;
    }
    &.five{
        background: pink;
    }
}
Menu