-
Hello! 👋I'm trying to make a Vue 3 component to output images. I would like to pass some information about the image to this component via props. And as soon as I do this, Parcel stops converting the images. I really tried, but couldn't find a solution to this predicament. Example AppImage.vue<script>
export default {
name: "AppImage",
props: {
width: {
type: Array,
default: () => [400, 800],
},
path: {
type: String,
default: '../image_01.jpg',
},
},
setup(props) {
const getImageUrl = (format, width) => {
return new URL(`${props.path}?as=${format}&width=${width}`, import.meta.url);
};
const getUrlSet = (format) => {
return props.width.map((width) => `${getImageUrl(format, width)}`).join(', ');
};
return {
getImageUrl,
getUrlSet,
props
};
},
};
</script>
<template lang="html">
<div class="image-container">
// It's working! 😊
<picture>
<source type="image/avif" srcset="../image_01.jpg?as=avif&width=400, ../image_01.jpg?as=avif&width=800">
<source type="image/webp" srcset="../image_01.jpg?as=webp&width=400, ../image_01.jpg?as=webp&width=800">
<source type="image/jpeg" srcset="../image_01.jpg?as=jpeg&width=400, ../image_01.jpg?as=jpeg&width=800">
<img src="../image_01.jpg" alt="">
</picture>
// It doesn't work 😔
<picture>
<source type="image/avif" :srcset="getUrlSet('avif')">
<source type="image/webp" :srcset="getUrlSet('webp')">
<source type="image/jpeg" :srcset="getUrlSet('jpeg')">
<img :src="`${props.path}`" alt="">
</picture>
</div>
</template> package.json
.parcelrc
|
Beta Was this translation helpful? Give feedback.
Answered by
mischnic
Sep 27, 2023
Replies: 1 comment
-
To make Parcel pick up the images, you need to have this code (literally) <source type="image/avif" srcset="../image_01.jpg?as=avif&width=400, ../image_01.jpg?as=avif&width=800"> or new URL("../image_01.jpg?as=avif&width=400, ../image_01.jpg?as=avif&width=800", import.meta.url) And not const x = "../image_01.jpg?as=avif&width=400, ../image_01.jpg?as=avif&width=800";
new URL(x, import.meta.url) Otherwise Parcel can't determine statically (without running your code) at build time which images to process |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
ux-ui-pro
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To make Parcel pick up the images, you need to have this code (literally)
or
And not
Otherwise Parcel can't determine statically (without running your code) at build time which images to process