<el-image :src="item.maUrl"></el-image> 如何在src处添加判断
时间: 2024-04-13 08:31:15 浏览: 18
您可以通过使用三元表达式在 `src` 属性中进行条件判断。以下是一个示例代码:
```
<el-image :src="item.maUrl ? item.maUrl : '默认图片路径'"></el-image>
```
在上述代码中,如果 `item.maUrl` 存在(非空),则将其赋值给 `src` 属性;否则,将使用指定的默认图片路径。您可以根据实际需求修改默认图片路径。
相关问题
<template v-if="item['type'] === 'img'"> <el-table-column :label="item.label" :prop="item.prop" align="center"> <template slot-scope="scope"> <el-image style="width: 50px; height: 50px" :src="scope.row.gooid" ></el-image> </template> </el-table-column> </template>这段代码中如何将goodid给替换成通用的id
在这段代码中,`scope.row.gooid` 表示当前行的 `gooid` 属性,如果要将其替换成通用的 `id` 属性,只需要将 `:src="scope.row.gooid"` 改成 `:src="scope.row.id"` 即可。修改后的代码如下:
```
<template v-if="item['type'] === 'img'">
<el-table-column :label="item.label" :prop="item.prop" align="center">
<template slot-scope="scope">
<el-image style="width: 50px; height: 50px" :src="scope.row.id"></el-image>
</template>
</el-table-column>
</template>
```
这样就可以通用地显示不同表格中的 `id` 属性了。
<template v-if="item['type'] === 'img'"> <el-table-column :label="item.label" :prop="item.prop" align="center"> <template slot-scope="scope"> <el-image style="width: 50px; height: 50px" :src="scope.row.goodurl" ></el-image> </template> </el-table-column> </template>这段代码中如何将goodimg给替换成通用的图片属性
在这段代码中,`scope.row.goodurl` 表示当前行的 `goodurl` 属性,如果要将其替换成通用的图片属性,只需要将 `:src="scope.row.goodurl"` 改成 `:src="scope.row.img"` 即可。修改后的代码如下:
```
<template v-if="item['type'] === 'img'">
<el-table-column :label="item.label" :prop="item.prop" align="center">
<template slot-scope="scope">
<el-image style="width: 50px; height: 50px" :src="scope.row.img"></el-image>
</template>
</el-table-column>
</template>
```
这样就可以通用地显示不同表格中的图片属性了。