本文介绍: vue3 + ts + element plus 的 el–table 和 el–radio 实现单选效果并设置不显示 label 文本,通过在 el–radio 标签中添加一个没有内容的标签来实现
单选框 radio 不显示 label 文本的关键,在 el–radio 标签中添加一个没有内容的标签
<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>
<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进行投诉反馈,一经查实,立即删除!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。