this problem is a bit difficult to describe. I describe it in more detail
1. There are four buttons on my page, all of which are to dynamically display ; each button corresponds to an independent flag, that can control the display of the button
<el-button v-if="!newLx" @click="addMind("newLx")"> + </el-button>
<el-button v-if="!newFl" @click="addMind("newFl")"> + </el-button>
<el-button v-if="!newYm" @click="addMind("newYm")"> + </el-button>
<el-button v-if="!newYx" @click="addMind("newYx")"> + </el-button>
<script>
export default {
data() {
newLx: false,
newFl: false,
newYm: false,
newYx: false
},
methods:{
addMind(type) { // ,
switch (type) {
case "newLx":
this.newLx = !this.newLx
break
case "newFl":
this.newFl = !this.newFl
break
case "newYm":
this.newYm = !this.newYm
break
case "newYx":
this.newYx = !this.newYx
break
}
}
}
</script>
Click the button, and the current button will disappear
2. The function is simple, but it doesn"t feel elegant, so I want to render the button in a for loop
< template Vmurf = "(item,index) in controlBtn" >
< el-button VMI if = ""+ (item.flag) +"" @ click= "addMind (item.flag)" > + {{item.name}} < / el-button >
< / template >
data: {
newLx: false,
newFl: false,
newYm: false,
newYx: false,
controlBtn: [
{"flag":"newLx","name":" New intention"},
{"flag":"newFl","name":" New training intention"},
{"flag":"newYm","name":" new overseas investment intention"},
{"flag":"newYx","name":" new study intention"},
]
}
but the value of v-if has not been taken correctly, and I don"t know how to get it.
because I still have to judge which button is displayed or not by the background data, so I think when echoing with the "newLx" corresponding to the top of the newLx: false, in controlBtn, I can directly control the newLx: false/true, and control whether the button is displayed or not.
do you have any elegant ways