一定要將靜態資源引入 【 require("@/assets/") 】,綁定到 模型綁定的:src 數據中 動態的數據才能有效
<template>
<div>
<el-card class="box-card">
<div slot="header" class="clearfix">
<span>動態列表</span>
<el-button style="float: right; padding: 3px 0" type="text">操作按鈕</el-button>
</div>
<div class="list">
<el-table
ref="multipleTable"
:data="dataPicture"
tooltip-effect="dark"
style="width: 100%"
@selection-change="handleSelectionChange">
<el-table-column
type="selection"
width="55">
</el-table-column>
<el-table-column
label="用戶"
width="120">
<template slot-scope="scope">{{ (scope.row.user).username }}</template>
</el-table-column>
<el-table-column
label="內容"
width="220">
<template slot-scope="scope">{{ scope.row.body }}</template>
</el-table-column>
<el-table-column
label="圖片"
width="220">
<template slot-scope="scope">
<div v-for="(img, index) in scope.row.imgArr" :key="index">
<img
:src="getImgUrl(img.path)" alt="" class="img">
</div>
</template>
</el-table-column>
<el-table-column
label="時間"
width="220">
<template slot-scope="scope">{{ scope.row.date }}</template>
</el-table-column>
<el-table-column
label="操作"
show-overflow-tooltip>
<template slot-scope="scope">
<el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
<el-button type="text" size="small">編輯</el-button>
</template>
</el-table-column>
</el-table>
</div>
</el-card>
</div>
</template>
<script>
export default {
data() {
return {
dataPicture:[],
}
},
methods: {
handleClick(row) {
console.log(row);
},
handleSelectionChange(val) {
// console.log(val);
this.multipleSelection = val;
},
getImgUrl(icon){
return require("@/assets/"+icon);
}
},
async created() {
var res = await this.$http.get('/picture')
this.dataPicture = res.data
// console.log(typeof this.dataPicture[0].user);
},
}
</script>
<style scoped>
.img{
width: 100px;
height: 100px;
}
</style>