Vue项目实战总结(五 插槽)

话不多说,直接开冲

<el-table :data="data" style="width: 100%">
  <el-table-column  align="center" label="一级标题" width="190" >
    <template slot-scope="scope">
      <div slot="reference" class="name-wrapper">
        <el-tag size="medium" v-bind:title1="scope.row.title1">{{ scope.row.title1 }}</el-tag>
      </div>
    </template>
  </el-table-column>

  <el-table-column align="center" label="二级标题" width="190">
    <template slot-scope="scope">
      <div slot="reference" class="name-wrapper">
        <el-tag size="medium">{{ scope.row.title2 }}</el-tag>
      </div>
    </template>
  </el-table-column>

  <el-table-column label="内容" align="center" width="550">
    <template slot-scope="scope">
      <div slot="reference" class="name-wrapper">
        <el-tag size="medium">{{ scope.row.content }}</el-tag>
      </div>
    </template>
  </el-table-column>

  <el-table-column label="操作" align="center" width="300">
    <template slot-scope="scope">
      <el-button
        type="text"
        icon="el-icon-edit"
        @click="handleEdit(scope.$index, scope.row)    
      >编辑</el-button>
      <el-button
        type="text"
        icon="el-icon-delete"
        class="red"
        @click="deleteIntroduction({id:scope.row.id})"
      >删除</el-button>
    </template>
  </el-table-column>
</el-table>

export default {
  data () {
    return {
      idx: -1,
      data:[{},{},{}],
    }
  },	
  methods: {
    handleEdit(index, row){
      this.idx = index;
      console.log("index", index, "row:", row)
      this.form = {
        title1: row.title1,
        title2: row.title2,
        content: row.content,
        id: row.id,
        father_id: row.father_id
      };
    },
    deleteIntroduction(query){
    	
    }
}

:data 绑定数组

scope.row代表获取当前行对象

@click="handleEdit(scope.$index, scope.row)

这里拿到每一行的index----------scope.$index

这里拿到每一行的数据-----------scope.$row

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值