
html
<el-select v-model="imgName" >
<template #prefix>
<img :src="getImageUrl(imgName)" v-if="imgName"/>
</template>
<el-option v-for="item in imgNameList" :label="item" :value="item">
<div class="option-container">
<img src="item.imgName"/>
</div>
</el-option>
</el-select>
javascript
const imgNameList = ref([
{
id:1,
imgName:'tupian'
}
])
function getImageUrl(name:string) {
return new URL(`.../assets/images/${name}.png`, import.meta.url).href
}
参考: