一、引言
二、准备图片资源
https://example.com/image1.jpg
https://example.com/image2.jpg
https://example.com/image3.jpg
三、创建 Vue Table
首先,我们需要在 Vue 项目中创建一个 Table 组件。以下是一个简单的示例:
<template>
<div>
<a-table :columns="columns" :data-source="dataSource" :pagination="false">
<template #image="{ text }">
<img :src="text" alt="图片展示" width="100" height="100" />
</template>
</a-table>
</div>
</template>
<script>
export default {
data() {
return {
dataSource: [
{ key: '1', image: 'https://example.com/image1.jpg' },
{ key: '2', image: 'https://example.com/image2.jpg' },
{ key: '3', image: 'https://example.com/image3.jpg' }
],
columns: [
{ title: '图片', dataIndex: 'image', key: 'image', slots: { customRender: 'image' } }
]
};
}
};
</script>
四、展示图片
五、优化性能
- 懒加载:只有当图片进入视口(viewport)时才加载图片,减少页面加载时间。
- 压缩图片:在服务器端或客户端压缩图片,减少图片大小,加快加载速度。
- CDN 加速:使用 CDN 加速图片的加载速度。