Install the Element Plus library as a dependency in your project:
npm install element-plus --save
Import the Image component and its dependencies in your Vue component:
import { defineComponent } from 'vue';
import { ElImage, ElLoading, ElMessageBox } from 'element-plus';
import 'element-plus/lib/theme-chalk/el-image.css';
import 'element-plus/lib/theme-chalk/el-loading.css';
import 'element-plus/lib/theme-chalk/el-message-box.css';
export default defineComponent({
components: {
ElImage,
ElLoading,
ElMessageBox,
},
// ...
});
Here, we've imported the Image component, as well as its dependencies (Loading and MessageBox), and their respective CSS files.
Use the Image component in your Vue template:
<template>
<div>
<el-image
src="https://picsum.photos/200/300"
fit="cover"
style="width: 200px; height: 300px;"
/>
</div>
</template>
Here, we've used the Image component with its src and fit props, and set its style with CSS.