Image image official document basic usage
<template>
<div class="demo-image">
<div v-for="fit in fits" :key="fit" class="block">
<span class="demonstration">{
{
fit }}</span>
<el-image style="width: 100px; height: 100px" :src="url" :fit="fit" />
</div>
</div>
</template>
<script lang="ts" setup>
const fits = ['fill', 'contain', 'cover', 'none', 'scale-down']
const url =
'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg'
</script>
Changed the url directly to a relative path, and found that the local image could not be imported, and the image failed. (In native img, images can be displayed using relative paths, such as: <img src="../../assets/img/xxx.jpg" alt="" class="img-fluid">
)
Vue uses relative paths to import local images/videos, and require() is required
const url= require('../../assets/img/xxx.jpg')
<div class="block">
<el-image style="width: 150px; height: 35px" :src="url" />
</div>