我正在使用Bootstrap-vue.JS
来制作一组单选按钮。我具有重置功能,可以选中单选按钮之一。当我调用该函数时,单选按钮的值已按预期更改,但单选按钮本身未显示其更改(圆圈未变为蓝色)
这是模板
<b-row md="9" align-h="center">
<b-form-group>
<b-form-radio-group
id="radio-group-1"
v-model="voc_type"
name="radio-options"
>
<b-form-radio value="Request">Request</b-form-radio>
<b-form-radio value="Complain">Complain</b-form-radio>
<b-form-radio value="Saran">Saran</b-form-radio>
<b-form-radio value="Pujian">Pujian</b-form-radio>
</b-form-radio-group>
</b-form-group>
</b-row>
{{ voc_type }}
这是创建vue
时的初始化
export default{
data{
return{
voc_type: 'Request',
}
}
}
这是重置功能
reset(){
this.voc_type= 'Request'
}
当我调用reset()
时,{{ voc_type }}
的输出如我所料是“请求”,但是单选按钮没有变成蓝色。 idk
为什么。
答案 0 :(得分:0)
我实现了一个重置按钮,现在可以正常使用了
<template>
<div>
<b-row md="9" align-h="center">
<b-form-group>
<b-form-radio-group id="radio-group-1" v-model="voc_type" name="radio-options">
<b-form-radio value="Request">Request</b-form-radio>
<b-form-radio value="Complain">Complain</b-form-radio>
<b-form-radio value="Saran">Saran</b-form-radio>
<b-form-radio value="Pujian">Pujian</b-form-radio>
</b-form-radio-group>
</b-form-group>
</b-row>
{{ voc_type }}
<b-btn @click="reset()">Reset</b-btn>
</div>
</template>
<script>
export default {
data() {
return {
voc_type: 'Request'
};
},
methods: {
reset() {
this.voc_type = 'Request';
}
}
};
</script>
由于此原因,Vue反应性可能无法正常工作,因此您的数据功能出现错字
data() { <-- correct this line
return {
voc_type: 'Request'
};
},