想把每个单元格变成button,然后可以触发事件,为什么添加后数据就没有了?

2023-06-21 329 0

<el-table :data="userList" border stripe>
        <el-table-column type="index" label="No." />
        <!--  v-for="col in columnList" :prop="col.prop" :label="col.label" :key="col.prop" -->
        <el-table-column label="姓名" prop="username">
          <template slot-scope="">
            <!-- <button type="text" v-model="scope.row.username"></el-button> -->
          </template>
        </el-table-column>
        <el-table-column label="邮箱" prop="email">
          <!-- <template slot-scope="scope">
            <el-button type="text" v-model="scope.row.email"></el-button>
          </template> -->
        </el-table-column>
        <el-table-column label="手机" prop="mobile">
          <!-- <template slot-scope="scope">
            <el-button type="text" v-model="scope.row.mobile"></el-button>
          </template> -->
        </el-table-column>
        <el-table-column label="角色" prop="role_name">
          <!-- <template slot-scope="scope">
            <el-button type="text" v-model="scope.row.role_name"></el-button>
          </template> -->
        </el-table-column>
        <el-table-column label="状态">
          <template slot-scope="scope">
            <el-switch v-model="scope.row.mg_state" @change="userStateChanged(scope.row)"></el-switch>
          </template>
        </el-table-column>

但是switch那里可以获取到

无论是button还是el-button都是在标签内部填充内容的,而不是靠v-model绑定值

Vue2:
elementUI
el-table-column上his不加prop属性的
image.png

Vue3:
element-plus 也是的
image.png

https://element-plus.gitee.io/zh-CN/component/table.html#%E8%...

是想这样吗?(改了其中姓名部分,变成文本点击按钮)

<template>
 <div>
    <el-table :data="userList" border stripe>
         <el-table-column type="index" label="No." />
        <!--  v-for="col in columnList" :prop="col.prop" :label="col.label" :key="col.prop" -->
        <el-table-column label="姓名" >
          <template slot-scope="scope">
            <el-button type="text" @click="handle(scope.row)">{{ scope.row.username }}</el-button>
          </template>
        </el-table-column>
        <el-table-column label="邮箱" prop="email">
          <!-- <template slot-scope="scope">
            <el-button type="text" v-model="scope.row.email"></el-button>
          </template> -->
        </el-table-column>
        <el-table-column label="手机" prop="mobile">
          <!-- <template slot-scope="scope">
            <el-button type="text" v-model="scope.row.mobile"></el-button>
          </template> -->
        </el-table-column>
        <el-table-column label="角色" prop="role_name">
          <!-- <template slot-scope="scope">
            <el-button type="text" v-model="scope.row.role_name"></el-button>
          </template> -->
        </el-table-column>
        <el-table-column label="状态">
          <template slot-scope="scope">
            <el-switch v-model="scope.row.mg_state" @change="userStateChanged(scope.row)"></el-switch>
          </template>
        </el-table-column>
    </el-table>
 </div>
</template>
<script>
 export default {
   components: {
   },
   data () {
     return {
        userList:[
            {
                username:'孙悟空',
                email:'13458633659@qq.com',
                mobile:'13456988654',
                role_name:'美猴王',
                mg_state:false,
            }
        ]
     }
   },
   computed:{
   },
   created(){
   },
   mounted(){
   },
   methods:{
    userStateChanged(row){
        console.log(row)
    },
    handle(row){
        console.log(row)
    }
   },
 }
</script>
<style scoped>
</style>

效果这样?
image.png

回答

相关文章

nuxt2部署静态化和ssr的时候访问首页先报404再出现首页为什么?
`clip-path` 如何绘制圆角平行四边形呢?
多线程wait方法报错?
VUE 绑定的方法如何直接使用外部函数?
vue2固定定位该怎么做?
谁有redis实现信号量的代码,希望借鉴一下?