[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
最近在写后台管理系统 在写到修改的地方时 之前的思路是直接把当前对象传过去 然后在进行修改
现在vue提供了scope 以及 scope.row 可以让我们更方便的操作数据
slot-scope='scope' 作用域插槽中定义一个对象(这里对象被定义为scope)来存储插槽上绑定的数据的用法
scope.row 使用ElementUI表格模板渲染数据时使用
当前行数据的获取也会用到插槽,scope相当于一行的数据, scope.row相当于当前行的数据对象
<el-table :data="userList" stripe style="width: 100%"> <el-table-column
prop="username"label="姓名" width="180"></el-table-column> <el-table-column
prop="email" label="邮箱" width="180"> </el-table-column> <el-table-column
prop="mobile" label="电话"> </el-table-column> <el-table-column label="用户状态">
<template slot-scope="scope"> <el-switch v-model="scope.row.mg_state"
@change="userstateChange(scope.row.id, scope.row.mg_state)"> </el-switch>
</template> </el-table-column> <el-table-column prop="adress" label="操作">
</el-table-column> </el-table>
:data ==》“userList”
表格绑定了用于存储数据的数组,里面每一个元素都是数据对象
slot-scope ==》“scope”
这是作用域插槽中定义一个对象(这里对象被定义为scope)来存储插槽上绑定的数据的用法
当前行的数据对象 ==》 scope.row
在这里使用ElementUI表格模板渲染数据时,
"当前行数据的获取也会用到插槽,scope相当于一行的数据, scope.row相当于当前行的数据对象
还是比较方便的~