element-ui,radio组件动态绑定选中项

使用element-ui的radio组件,当label的值等于v-model的值时,radio就会默认选中此项,但是当v-model的值是动态时,你会发现根本选中不了

 

 

解决方案:使用 this.$set 对v-model的值进行赋值

 

 

如:以下为请求后端数据

then(response => {

    if (response.code === 1) {

        this.$set(this.upForm, 'type', response.data)

    }

})

 

注:有个大坑,如果后端返回response.data 数据是数字类型的,那需要转成字符串,不然也是不显示的

 

 

猜你喜欢

转载自blog.csdn.net/Chen_start02/article/details/87830832