export default {
props: {
imgPath: {
type: String,
required: true,
},
},
computed() {
webpPath() {
return require(this.imgPath + '.jpg') // Будет ошибка при попытке require
},
jpgPath() {
return require(this.imgPath + '.webp') // Будет ошибка при попытке require
}
},
}
<img src="@assets/images/logo.png" /> это равносильно <img :src="require('@assets/images/logo.png')" /> в рамках Vue шаблонану да, require вообще не для этого нужен, он там ни к чемуа для чего от тогда вообще? Разве не для подключения модулей? В рамках вебпака - все модуль, и картинка тоже.
<script>
export default {
props: {
src: {
type: String,
required: true,
},
},
}
</script>
<template>
<picture>
<source :srcset="srcWebp" type="image/webp" />
<source :srcset="srcJpg" type="image/jpg" />
<img decoding="async" loading="lazy" />
</picture>
</template>
computed() {
webpPath() {
return 'directory-with-jpgs/' + this.imgPath + '.jpg'
},
jpgPath() {
return 'directory-with-webps/' + this.imgPath + '.webp'
}
}