vxe-radio-group 组件接受 string 类型数据直接回显。通过设置 v-model 绑定数据,当选中某个 radio 时,组件会将对应的 value 值赋给 v-model 绑定的数据,因此在回显时,只需要将该数据设置为 v-model 的初始值即可。

例如:

<template>
  <div>
    <vxe-radio-group v-model="fruit">
      <vxe-radio label="apple">苹果</vxe-radio>
      <vxe-radio label="banana">香蕉</vxe-radio>
      <vxe-radio label="orange">橙子</vxe-radio>
    </vxe-radio-group>
    <p>你选择的水果是:{{ fruit }}</p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      fruit: 'apple' // 初始值为 'apple'
    }
  }
}
</script>

在上面的代码中,当用户选择某个水果时,v-model 绑定的 fruit 数据会自动更新,因此在页面中显示的选择结果也会跟着更新。在页面初始化时,组件会根据 fruit 的初始值自动选中对应的 radio

vxe-radio-group 接受string类型数据直接回显

原文地址: https://www.cveoy.top/t/topic/d5lP 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录