elemenui中的el-table表中使用图片el-img

错误示范:

<el-table v-loading="loading" :data="productList" @selection-change="handleSelectionChange">
	<el-table-column label="商品规格" align="center" prop="productSpecification" width="125">
	     <div class="demo-image__preview">
	       <el-image 
	         style="width: 100px; height: 100px"
	         :src="productSpecification" >
	       </el-image>
	     </div>
	 </el-table-column>
 </el-table>

el-table-clumn中使用v-bind元素,是不能获取el-table正在进行展示的数据的所以上述代码并不能在单元格内展示图片。
elementUI显然考虑到了这一点,为我们提供了内置属性slot-scope,
通过访问其内置的row属性可以访问到表格每一列的变量名。

正确写法:

<el-table v-loading="loading" :data="productList" @selection-change="handleSelectionChange">
	<template slot-scope="scope">
       <div class="demo-image__preview">
         <el-image 
           style="width: 100px; height: 100px"
           :src="scope.row.productSpecification" >
         </el-image>
       </div>
     </template>
</el-table>

与错误示例的主要区别是给需要用到属性的元素的父元素指定 slot-scope = “scope”,并在 :src 的路径指定通过 scope.row.XX的形式指定

猜你喜欢

转载自blog.csdn.net/weilaaer/article/details/131005527