单选框 radio显示 label 文本的关键,在 elradio 标签添加一个没有内容标签

 <el-table-column width="50px" align="center">
   <template #default="scope">
     <el-radio v-model="radio" :label="scope.row.id">
       <span></span>
     </el-radio&gt;
   </template&gt;
 </el-table-column&gt;

完整如下

<template>
  <el-table
    ref="singleTableRef"
    :data="tableData"
    style="width: 100%"
    @current-change="handleCurrentChange"
  >
    <el-table-column width="50px" align="center">
      <template #default="scope">
        <el-radio v-model="radio" :label="scope.row.id">
          <span></span>
        </el-radio>
      </template>
    </el-table-column>
    <el-table-column type="index" width="50" />
    <el-table-column property="date" label="Date" width="120" />
    <el-table-column property="name" label="Name" width="120" />
    <el-table-column property="address" label="Address" />
  </el-table>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import { ElTable } from "element-plus";

interface User {
  id: number;
  date: string;
  name: string;
  address: string;
}

const currentRow = ref();
const radio = ref<number>();
const singleTableRef = ref<InstanceType<typeof ElTable>>();

const handleCurrentChange = (row: User | undefined) => {
  currentRow.value = row;
  radio.value = row?.id;
};
const tableData: User[] = [
  {
    id: 1,
    date: "2016-05-03",
    name: "Tom",
    address: "No. 189, Grove St, Los Angeles",
  },
  {
    id: 2,
    date: "2016-05-02",
    name: "Tom",
    address: "No. 189, Grove St, Los Angeles",
  },
  {
    id: 3,
    date: "2016-05-04",
    name: "Tom",
    address: "No. 189, Grove St, Los Angeles",
  },
  {
    id: 4,
    date: "2016-05-01",
    name: "Tom",
    address: "No. 189, Grove St, Los Angeles",
  },
];
</script>

原文地址:https://blog.csdn.net/nana_lala/article/details/131320858

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_26094.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注