I might miss some basic vue.js knowledge, but I have the following question related to <picture> and specifically srcset
I have different formats of the same image coming from my api, like this:
"posts": [
{
"image": {
"formats": {
"thumbnail": {
"hash": "thumbnail_image",
"ext": ".png",
"mime": "image/png",
"width": 245,
"height": 138,
"size": 76.89,
"url": "/uploads/thumbnail_image.png"
},
"large": {
"hash": "large_image",
"ext": ".png",
"mime": "image/png",
"width": 1000,
"height": 563,
"size": 916.23,
"url": "/uploads/large_image.png"
},
"medium": {
"hash": "medium_image",
"ext": ".png",
"mime": "image/png",
"width": 750,
"height": 422,
"size": 562.28,
"url": "/uploads/medium_image.png"
},
"small": {
"hash": "small_image",
"ext": ".png",
"mime": "image/png",
"width": 500,
"height": 281,
"size": 275.16,
"url": "/uploads/small_image.png"
}
}
}
},
The final results I want to obtain is something like:
<picture>
<source srcset="https://apiurl.com/large_image.png 1000w, https://apiurl.com/medium_image.png 750w, https://apiurl.com/small_image.png 500w" />
</picture>
I am already passing all of the formats as a prop into the component, so they are all stored as "images"
basically what I would like is to have a single source that can loop through the formats (not necessarily there's always large or small) and add the URL inside :srcset.
Of course I am able to do
<source v-for="format in images" :srcset="apiUrl + format.url">
which works but generates multiple source
What's the best approach or solution for this situation?
Thanks
Simple Solution:
If you don't want to use computed or a component, you could just use a method where you pass a post and it returns the srcset urls.
methods: {
postSrcSetUrls(post) {
if (!post || !post.image || !post.image.formats)
return null;
let sizes = Object.keys(post.image.formats);
return sizes.map(size => `${post.image.formats[size].url} ${post.image.formats[size].width}w`).join(", ");
}
}
Then, in your template
<picture v-for="post in posts">
<source :srcset="postSrcSetUrls(post)" />
</picture>
Computed / Component Solution:
I would make a component and use a computed property for what you're trying to do. You can then use Object.keys to get the names of the format sizes, which can then be used to loop through your formats.
I've included a snippet below, which you'll probably want to change a little, for example to include your api url.
This uses the Props, Computed Properties, Template Syntax, List Rendering and Component Registration sections of the documentation, that might be useful.
Vue.component("post-image-formats", {
template: "<div><strong>Src Set Url</strong><br /> {{srcsetUrl}}</div>",
props: ["formats"],
computed: {
srcsetUrl() {
if (!this.formats)
return null;
let sizes = Object.keys(this.formats);
return sizes.map(size => `${this.formats[size].url} ${this.formats[size].width}w`).join(", ");
}
}
});
let posts = [{
"image": {
"formats": {
"thumbnail": {
"hash": "thumbnail_image",
"ext": ".png",
"mime": "image/png",
"width": 245,
"height": 138,
"size": 76.89,
"url": "/uploads/thumbnail_image.png"
},
"large": {
"hash": "large_image",
"ext": ".png",
"mime": "image/png",
"width": 1000,
"height": 563,
"size": 916.23,
"url": "/uploads/large_image.png"
},
"medium": {
"hash": "medium_image",
"ext": ".png",
"mime": "image/png",
"width": 750,
"height": 422,
"size": 562.28,
"url": "/uploads/medium_image.png"
},
"small": {
"hash": "small_image",
"ext": ".png",
"mime": "image/png",
"width": 500,
"height": 281,
"size": 275.16,
"url": "/uploads/small_image.png"
}
}
}
},
{
"image": {
"formats": {
"thumbnail": {
"hash": "thumbnail_image",
"ext": ".png",
"mime": "image/png",
"width": 245,
"height": 138,
"size": 76.89,
"url": "/uploads/thumbnail_image.png"
},
"large": {
"hash": "large_image",
"ext": ".png",
"mime": "image/png",
"width": 1000,
"height": 563,
"size": 916.23,
"url": "/uploads/large_image.png"
},
"medium": {
"hash": "medium_image",
"ext": ".png",
"mime": "image/png",
"width": 750,
"height": 422,
"size": 562.28,
"url": "/uploads/medium_image.png"
},
"small": {
"hash": "small_image",
"ext": ".png",
"mime": "image/png",
"width": 500,
"height": 281,
"size": 275.16,
"url": "/uploads/small_image.png"
}
}
}
}
];
new Vue({
el: "#app",
data: () => {
return {
posts: posts
};
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<div>
<post-image-formats v-for="post in posts" :formats="post.image.formats"></post-image-formats>
</div>
</div>
Related
I am trying to fish data with images but how can I do two map inside each othe I need only the first image from every item
here is the JSON file
`
"items": Array [
Object {
"external_urls": Object {
"spotify": "https://open.spotify.com/artist/5staYrHq4jR1NiBfRR2XWr",
},
"followers": Object {
"href": null,
"total": 433,
},
"genres": Array [],
"href": "https://api.spotify.com/v1/artists/5staYrHq4jR1NiBfRR2XWr",
"id": "5staYrHq4jR1NiBfRR2XWr",
"images": Array [
Object {
"height": 640,
"url": "https://i.scdn.co/image/ab6761610000e5eb038f9071ec89962e7ad16b77",
"width": 640,
},
Object {
"height": 320,
"url": "https://i.scdn.co/image/ab67616100005174038f9071ec89962e7ad16b77",
"width": 320,
},
Object {
"height": 160,
"url": "https://i.scdn.co/image/ab6761610000f178038f9071ec89962e7ad16b77",
"width": 160,
},
],
"name": "DOXX",
"popularity": 6,
"type": "artist",
"uri": "spotify:artist:5staYrHq4jR1NiBfRR2XWr",
},
Object {
"external_urls": Object {
"spotify": "https://open.spotify.com/artist/1MVFEpYdHtdV3k8Bgs79Pl",
},
"followers": Object {
"href": null,
"total": 404,
},
"genres": Array [],
"href": "https://api.spotify.com/v1/artists/1MVFEpYdHtdV3k8Bgs79Pl",
"id": "1MVFEpYdHtdV3k8Bgs79Pl",
"images": Array [
Object {
"height": 640,
"url": "https://i.scdn.co/image/ab6761610000e5ebd1578a57ff89ac9aeed23863",
"width": 640,
},
Object {
"height": 320,
"url": "https://i.scdn.co/image/ab67616100005174d1578a57ff89ac9aeed23863",
"width": 320,
},
Object {
"height": 160,
"url": "https://i.scdn.co/image/ab6761610000f178d1578a57ff89ac9aeed23863",
"width": 160,
},
],
"name": "DOXY",
"popularity": 14,
"type": "artist",
"uri": "spotify:artist:1MVFEpYdHtdV3k8Bgs79Pl",
},
Object {
"external_urls": Object {
"spotify": "https://open.spotify.com/artist/1HliyC4gHWRHHFy3CjR3Bp",
},
"followers": Object {
"href": null,
"total": 2,
},
"genres": Array [],
"href": "https://api.spotify.com/v1/artists/1HliyC4gHWRHHFy3CjR3Bp",
"id": "1HliyC4gHWRHHFy3CjR3Bp",
"images": Array [],
"name": "Doxy601",
"popularity": 5,
"type": "artist",
"uri": "spotify:artist:1HliyC4gHWRHHFy3CjR3Bp",
},
Object {
"external_urls": Object {
"spotify": "https://open.spotify.com/artist/7d8a8D8ZfVdYsuAcMk4Kxy",
},
"followers": Object {
"href": null,
"total": 97,
},
"genres": Array [],
"href": "https://api.spotify.com/v1/artists/7d8a8D8ZfVdYsuAcMk4Kxy",
"id": "7d8a8D8ZfVdYsuAcMk4Kxy",
"images": Array [
Object {
"height": 640,
"url": "https://i.scdn.co/image/ab67616d0000b2736862f6dfd64d0c65d70c4623",
"width": 640,
},
Object {
"height": 300,
"url": "https://i.scdn.co/image/ab67616d00001e026862f6dfd64d0c65d70c4623",
"width": 300,
},
Object {
"height": 64,
"url": "https://i.scdn.co/image/ab67616d000048516862f6dfd64d0c65d70c4623",
"width": 64,
},
],
"name": "Miles Davis & Milt Jackson",
"popularity": 5,
"type": "artist",
"uri": "spotify:artist:7d8a8D8ZfVdYsuAcMk4Kxy",
},
Object {
"external_urls": Object {
"spotify": "https://open.spotify.com/artist/6NrhhuvYUPDmZ7RiZAWQih",
},
"followers": Object {
"href": null,
"total": 546,
},
"genres": Array [],
"href": "https://api.spotify.com/v1/artists/6NrhhuvYUPDmZ7RiZAWQih",
"id": "6NrhhuvYUPDmZ7RiZAWQih",
"images": Array [
Object {
"height": 640,
"url": "https://i.scdn.co/image/ab6761610000e5ebe2cae73d43e39e83aebc2bf5",
"width": 640,
},
Object {
"height": 320,
"url": "https://i.scdn.co/image/ab67616100005174e2cae73d43e39e83aebc2bf5",
"width": 320,
},
Object {
"height": 160,
"url": "https://i.scdn.co/image/ab6761610000f178e2cae73d43e39e83aebc2bf5",
"width": 160,
},
],
"name": "DOX",
"popularity": 25,
"type": "artist",
"uri": "spotify:artist:6NrhhuvYUPDmZ7RiZAWQih",
},
Object {
"external_urls": Object {
"spotify": "https://open.spotify.com/artist/6792Ts7YzD8dhGkgSHPNEL",
},
"followers": Object {
"href": null,
"total": 125,
},
"genres": Array [],
"href": "https://api.spotify.com/v1/artists/6792Ts7YzD8dhGkgSHPNEL",
"id": "6792Ts7YzD8dhGkgSHPNEL",
"images": Array [
Object {
"height": 640,
"url": "https://i.scdn.co/image/ab67616d0000b273e2318a139e0f022870baac23",
"width": 640,
},
Object {
"height": 300,
"url": "https://i.scdn.co/image/ab67616d00001e02e2318a139e0f022870baac23",
"width": 300,
},
Object {
"height": 64,
"url": "https://i.scdn.co/image/ab67616d00004851e2318a139e0f022870baac23",
"width": 64,
},
],
"name": "Miles Davis And Milt Jackson Sextet",
"popularity": 1,
"type": "artist",
"uri": "spotify:artist:6792Ts7YzD8dhGkgSHPNEL",
},
Object {
"external_urls": Object {
"spotify": "https://open.spotify.com/artist/2b69LpXVfEagXEJpHjj3vW",
},
"followers": Object {
"href": null,
"total": 10,
},
"genres": Array [],
"href": "https://api.spotify.com/v1/artists/2b69LpXVfEagXEJpHjj3vW",
"id": "2b69LpXVfEagXEJpHjj3vW",
"images": Array [
Object {
"height": 640,
"url": "https://i.scdn.co/image/ab6761610000e5eb634c7182d6152094085cf475",
"width": 640,
},
Object {
"height": 320,
"url": "https://i.scdn.co/image/ab67616100005174634c7182d6152094085cf475",
"width": 320,
},
Object {
"height": 160,
"url": "https://i.scdn.co/image/ab6761610000f178634c7182d6152094085cf475",
"width": 160,
},
],
"name": "XODUS MMXXI",
"popularity": 12,
"type": "artist",
"uri": "spotify:artist:2b69LpXVfEagXEJpHjj3vW",
},
Object {
"external_urls": Object {
"spotify": "https://open.spotify.com/artist/1IhDCe20UkuG9o00cnhvS8",
},
"followers": Object {
"href": null,
"total": 106,
},
"genres": Array [],
"href": "https://api.spotify.com/v1/artists/1IhDCe20UkuG9o00cnhvS8",
"id": "1IhDCe20UkuG9o00cnhvS8",
"images": Array [
Object {
"height": 640,
"url": "https://i.scdn.co/image/ab67616d0000b273802c20b22f713bf4ca551ea9",
"width": 640,
},
Object {
"height": 300,
"url": "https://i.scdn.co/image/ab67616d00001e02802c20b22f713bf4ca551ea9",
"width": 300,
},
Object {
"height": 64,
"url": "https://i.scdn.co/image/ab67616d00004851802c20b22f713bf4ca551ea9",
"width": 64,
},
],
"name": "Doxi",
"popularity": 11,
"type": "artist",
"uri": "spotify:artist:1IhDCe20UkuG9o00cnhvS8",
},
Object {
"external_urls": Object {
"spotify": "https://open.spotify.com/artist/0joBZjd7WSxAGlRC2pvaJM",
},
"followers": Object {
"href": null,
"total": 0,
},
"genres": Array [],
"href": "https://api.spotify.com/v1/artists/0joBZjd7WSxAGlRC2pvaJM",
"id": "0joBZjd7WSxAGlRC2pvaJM",
"images": Array [
Object {
"height": 640,
"url": "https://i.scdn.co/image/ab67616d0000b27375b17d2e3f94ae1bddd65046",
"width": 640,
},
Object {
"height": 300,
"url": "https://i.scdn.co/image/ab67616d00001e0275b17d2e3f94ae1bddd65046",
"width": 300,
},
Object {
"height": 64,
"url": "https://i.scdn.co/image/ab67616d0000485175b17d2e3f94ae1bddd65046",
"width": 64,
},
],
"name": "Prod.Dozy",
"popularity": 1,
"type": "artist",
"uri": "spotify:artist:0joBZjd7WSxAGlRC2pvaJM",
},
`
I did this to map data {items.map((data,i)=>({data.name}))}
I do this and it works but I want also to get the first image for each item can I do two maps inside each other ??
but how I can get these data with the first image for every item
You can load multiple items from an array using just one map.
To get the first image of every item you'll have to access the first item from the image array [0] and from that image you'll need the url to fill the source property of an <Image/> component (from React Native). You'll also need to supply the width and height to the style property like so:
{items.map((data) => ( <>
<Image style={{width: `${data.images[0].width}`, height: `${data.images[0].height}` }} source={require(`${data.images[0].url}`)}/>
<div>{data.name}</div> </>))}
I also wrapped Image and div in a React fragment: <></>
How do I print the URI value from this response?
Response = {"assets": [{"fileName": "rn_image_picker_lib_temp73410.jpg", "fileSize": 208402, "height": 1280, "type": "image/jpeg", "uri": "file:///data/user/0/com.react/cache/rn_image_picker_lib_temp73410.jpg", "width": 1028}]}
You can achieve it doing like this:
let Response = {
"assets": [
{
"fileName": "rn_image_picker_lib_temp73410.jpg",
"fileSize": 208402,
"height": 1280,
"type": "image/jpeg",
"uri": "file:///data/user/0/com.react/cache/rn_image_picker_lib_temp73410.jpg",
"width": 1028
}
]
}
Response.assets[0].uri
I have a postgres table with a column (information) that looks like this
[
{
"col": "title",
"source": film.title
"width": 100
},
{
"col": "director",
"source": film.director,
"width": 150
},
{
"col": "year",
"source": film.releaseyear,
"width": 40
}
]
How do I add to array after the director element so it looks like this
[
{
"col": "title",
"source": film.title
"width": 100
},
{
"col": "director",
"source": film.director,
"width": 150
},
{
"col": "length",
"source": film.duration,
"width": 50
},
{
"col": "year",
"source": film.releaseyear,
"width": 40
}
]
I know it's the jsonb_insert function but I'm not sure what the path should be. I tried
jsonb_insert(information, {1}, filmLength::jsonb, true) but that doesn't work.
My confusion is that the array I'm inserting into is the whole json not just a key/value in the object.
When making a request to:
https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&maxResults=5&key=<MY_API_KEY>&q=dogs
I get the following error response:
"error": {
"code": 403,
"message": "Requests from referer \u003cempty\u003e are blocked.",
"errors": [
{
"message": "Requests from referer \u003cempty\u003e are blocked.",
"domain": "global",
"reason": "forbidden"
}
],
"status": "PERMISSION_DENIED",
"details": [
{
"#type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "API_KEY_HTTP_REFERRER_BLOCKED",
"domain": "googleapis.com",
"metadata": {
"consumer": "projects/119952101582",
"service": "youtube.googleapis.com"
}
}
]
}
}
The error is because the http referrer of the request violates API key HTTP restrictions.
Check your API_KEY settings of your project.
You can try the request in the documentation feature and see the results:
URL: https://youtube.googleapis.com/youtube/v3/search?part=snippet&maxResults=5&type=video&key=[YOUR_API_KEY]
Results:
{
"kind": "youtube#searchListResponse",
"etag": "4Jd7oMmX6dodoqxeiB24wLkVMPY",
"nextPageToken": "CAUQAA",
"regionCode": "CO",
"pageInfo": {
"totalResults": 1000000,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "ZQVJo2CIwtFFTHVA4hq4gLBld_w",
"id": {
"kind": "youtube#video",
"videoId": "Ci3TMqWfNLs"
},
"snippet": {
"publishedAt": "2020-09-17T22:08:22Z",
"channelId": "UCKTWUJqT3NSZ50I49ExjWZQ",
"title": "Master KG - Jerusalema feat. Micro TDH & Greeicy & Nomcebo Zikode – [Remix] (Official Video)",
"description": "Master KG - Jerusalema feat. Micro TDH & Greeicy & Nomcebo Zikode – [Remix] (Official Video) SUBSCRIBETE ▷ https://war.lnk.to/subscribe Ya disponible en ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/Ci3TMqWfNLs/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/Ci3TMqWfNLs/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/Ci3TMqWfNLs/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Warner Música",
"liveBroadcastContent": "none",
"publishTime": "2020-09-17T22:08:22Z"
}
},
{
"kind": "youtube#searchResult",
"etag": "vgvtwWrC2W3mxKzGxE2tL8K5xC4",
"id": {
"kind": "youtube#video",
"videoId": "dZauWAlZwl4"
},
"snippet": {
"publishedAt": "2020-12-04T00:00:08Z",
"channelId": "UCEFNzT2RoVqGkV4e3Osyx4A",
"title": "Piso 21 & Maluma - Más De La Una (Video Oficial)",
"description": "Piso 21 & Maluma - Más De La Una (Video Oficial) Suscríbete ahora al canal oficial de Piso 21: http://bit(.)ly/Piso21 Escucha todos los éxitos de Piso 21 aquí: ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/dZauWAlZwl4/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/dZauWAlZwl4/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/dZauWAlZwl4/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Piso 21",
"liveBroadcastContent": "none",
"publishTime": "2020-12-04T00:00:08Z"
}
},
{
"kind": "youtube#searchResult",
"etag": "KUGKha-wikLcojZUG_IFiIDfqns",
"id": {
"kind": "youtube#video",
"videoId": "zLX_GcXt2pI"
},
"snippet": {
"publishedAt": "2015-10-15T05:00:01Z",
"channelId": "UC5imdbLT1yRvjbyqeHhnt0A",
"title": "Manuel Medrano - Bajo El Agua (Video Oficial)",
"description": "Descarga en iTunes: https://itunes.apple.com/co/album/bajo-el-agua-single/id1015028641 Adquiere en Google Play: ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/zLX_GcXt2pI/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/zLX_GcXt2pI/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/zLX_GcXt2pI/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Manuel Medrano",
"liveBroadcastContent": "none",
"publishTime": "2015-10-15T05:00:01Z"
}
},
{
"kind": "youtube#searchResult",
"etag": "w6n0QzKBHByHu-HNiG8Lh3SkNUA",
"id": {
"kind": "youtube#video",
"videoId": "0EqHqPvXcMU"
},
"snippet": {
"publishedAt": "2019-09-06T05:00:04Z",
"channelId": "UCEFNzT2RoVqGkV4e3Osyx4A",
"title": "Piso 21 & Christian Nodal - Pa' Olvidarme De Ella (Video Oficial)",
"description": "No olvides suscribirte al canal de Piso 21 para ver los últimos videos musicales oficiales, audio oficial, álbumes y más! Sigue a Piso 21 en: Facebook: ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/0EqHqPvXcMU/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/0EqHqPvXcMU/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/0EqHqPvXcMU/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Piso 21",
"liveBroadcastContent": "none",
"publishTime": "2019-09-06T05:00:04Z"
}
},
{
"kind": "youtube#searchResult",
"etag": "wHEXK_WA_JcIMFQ89iipYVAxp7U",
"id": {
"kind": "youtube#video",
"videoId": "W4dioKwTm1A"
},
"snippet": {
"publishedAt": "2021-10-15T00:00:12Z",
"channelId": "UClZuKq2m0Qu-HkopkSBLpEw",
"title": "Lalo Ebratt, Maluma - Sukutubla (Official Video)",
"description": "Lalo Ebratt, Maluma - Sukutubla (Official Video) Top Hits: https://smarturl.it/malumatophits My Channel: https://smarturl.it/ytmaluma Maluma: ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/W4dioKwTm1A/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/W4dioKwTm1A/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/W4dioKwTm1A/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Maluma",
"liveBroadcastContent": "none",
"publishTime": "2021-10-15T00:00:12Z"
}
}
]
}
I know it's a similar question to others here but none of the previous solutions were successful for me.
I have a gallery page that works well getting the collections from Strapi, opening a dynamic page but I can't manage how to show the images there.
I'm calling my gallery and getting all the details but IDK how to show it in the correct way on the v-for
Here's how I'm calling the specific gallery (_slug.vue page)
async asyncData({ $strapi, params }) {
const gallery = await $strapi.find("galleries", {
slug: params.slug
});
console.log(gallery);
return {
gallery
};
},
And here how I'm I'm trying to display it
<h2 class="text-2xl font-normal text-gray-600 mt-12 mb-3">{{ gallery.title }}</h2>
<p class="mb-10 text-lg font-light text-gray-700">{{ gallery.description }}</p>
<div class="inline-flex flex-wrap">
<div v-for="item of gallery" class="w-full md:w-1/2 lg:w-1/3 xl:1/4 p-4">
<img
class="w-full h-96 object-cover rounded transition ease-in-out transform hover:-translate-y-1 hover:shadow-xl hover"
:src="$config.strapiUrl + item.gallery.images[0].url"
alt=""
/>
</div>
</div>
The $config.strapiUrl URL variable works well on all other pages. I don't believe the issue is with that but how I'm calling/or not calling. I'm not getting any images, title nor description but they are on the API response.
API Response I'm getting is
[
{
"id": 6,
"title": "Gallery 2",
"description": "Description here",
"published_at": "2021-10-23T20:47:50.752Z",
"created_at": "2021-10-23T20:47:46.503Z",
"updated_at": "2021-10-23T20:53:51.527Z",
"slug": "gallery-2",
"images": [
{
"id": 169,
"name": "002_01.jpg",
"alternativeText": "",
"caption": "",
"width": 1600,
"height": 1066,
"formats": {
"large": {
"ext": ".jpg",
"url": "/uploads/large_002_01_6943cf5aac.jpg",
"hash": "large_002_01_6943cf5aac",
"mime": "image/jpeg",
"name": "large_002_01.jpg",
"path": null,
"size": 74.3,
"width": 1000,
"height": 666
},
"small": {
"ext": ".jpg",
"url": "/uploads/small_002_01_6943cf5aac.jpg",
"hash": "small_002_01_6943cf5aac",
"mime": "image/jpeg",
"name": "small_002_01.jpg",
"path": null,
"size": 25.5,
"width": 500,
"height": 333
},
"medium": {
"ext": ".jpg",
"url": "/uploads/medium_002_01_6943cf5aac.jpg",
"hash": "medium_002_01_6943cf5aac",
"mime": "image/jpeg",
"name": "medium_002_01.jpg",
"path": null,
"size": 46.64,
"width": 750,
"height": 500
},
"thumbnail": {
"ext": ".jpg",
"url": "/uploads/thumbnail_002_01_6943cf5aac.jpg",
"hash": "thumbnail_002_01_6943cf5aac",
"mime": "image/jpeg",
"name": "thumbnail_002_01.jpg",
"path": null,
"size": 8.53,
"width": 234,
"height": 156
}
},
"hash": "002_01_6943cf5aac",
"ext": ".jpg",
"mime": "image/jpeg",
"size": 164.23,
"url": "/uploads/002_01_6943cf5aac.jpg",
"previewUrl": null,
"provider": "local",
"provider_metadata": null,
"created_at": "2021-10-23T18:37:15.745Z",
"updated_at": "2021-10-23T18:37:15.842Z"
},
{
"id": 178,
"name": "002_02.jpg",
"alternativeText": "",
"caption": "",
"width": 1600,
"height": 1066,
"formats": {
"large": {
"ext": ".jpg",
"url": "/uploads/large_002_02_32ff961c52.jpg",
"hash": "large_002_02_32ff961c52",
"mime": "image/jpeg",
"name": "large_002_02.jpg",
"path": null,
"size": 117.43,
"width": 1000,
"height": 666
},
"small": {
"ext": ".jpg",
"url": "/uploads/small_002_02_32ff961c52.jpg",
"hash": "small_002_02_32ff961c52",
"mime": "image/jpeg",
"name": "small_002_02.jpg",
"path": null,
"size": 33.45,
"width": 500,
"height": 333
},
"medium": {
"ext": ".jpg",
"url": "/uploads/medium_002_02_32ff961c52.jpg",
"hash": "medium_002_02_32ff961c52",
"mime": "image/jpeg",
"name": "medium_002_02.jpg",
"path": null,
"size": 68.17,
"width": 750,
"height": 500
},
"thumbnail": {
"ext": ".jpg",
"url": "/uploads/thumbnail_002_02_32ff961c52.jpg",
"hash": "thumbnail_002_02_32ff961c52",
"mime": "image/jpeg",
"name": "thumbnail_002_02.jpg",
"path": null,
"size": 8.68,
"width": 234,
"height": 156
}
},
"hash": "002_02_32ff961c52",
"ext": ".jpg",
"mime": "image/jpeg",
"size": 247.96,
"url": "/uploads/002_02_32ff961c52.jpg",
"previewUrl": null,
"provider": "local",
"provider_metadata": null,
"created_at": "2021-10-23T18:37:20.647Z",
"updated_at": "2021-10-23T18:37:20.850Z"
},
{
"id": 183,
"name": "002_04.jpg",
"alternativeText": "",
"caption": "",
"width": 1600,
"height": 1066,
"formats": {
"large": {
"ext": ".jpg",
"url": "/uploads/large_002_04_863abe8b86.jpg",
"hash": "large_002_04_863abe8b86",
"mime": "image/jpeg",
"name": "large_002_04.jpg",
"path": null,
"size": 122.13,
"width": 1000,
"height": 666
},
"small": {
"ext": ".jpg",
"url": "/uploads/small_002_04_863abe8b86.jpg",
"hash": "small_002_04_863abe8b86",
"mime": "image/jpeg",
"name": "small_002_04.jpg",
"path": null,
"size": 32.98,
"width": 500,
"height": 333
},
"medium": {
"ext": ".jpg",
"url": "/uploads/medium_002_04_863abe8b86.jpg",
"hash": "medium_002_04_863abe8b86",
"mime": "image/jpeg",
"name": "medium_002_04.jpg",
"path": null,
"size": 68.82,
"width": 750,
"height": 500
},
"thumbnail": {
"ext": ".jpg",
"url": "/uploads/thumbnail_002_04_863abe8b86.jpg",
"hash": "thumbnail_002_04_863abe8b86",
"mime": "image/jpeg",
"name": "thumbnail_002_04.jpg",
"path": null,
"size": 8.61,
"width": 234,
"height": 156
}
},
"hash": "002_04_863abe8b86",
"ext": ".jpg",
"mime": "image/jpeg",
"size": 280.6,
"url": "/uploads/002_04_863abe8b86.jpg",
"previewUrl": null,
"provider": "local",
"provider_metadata": null,
"created_at": "2021-10-23T18:37:22.628Z",
"updated_at": "2021-10-23T18:37:22.931Z"
}
],
"cover_image": {
"id": 167,
"name": "002_10.jpg",
"alternativeText": "",
"caption": "",
"width": 1600,
"height": 1066,
"formats": {
"large": {
"ext": ".jpg",
"url": "/uploads/large_002_10_b20570c2ca.jpg",
"hash": "large_002_10_b20570c2ca",
"mime": "image/jpeg",
"name": "large_002_10.jpg",
"path": null,
"size": 59.87,
"width": 1000,
"height": 666
},
"small": {
"ext": ".jpg",
"url": "/uploads/small_002_10_b20570c2ca.jpg",
"hash": "small_002_10_b20570c2ca",
"mime": "image/jpeg",
"name": "small_002_10.jpg",
"path": null,
"size": 20.34,
"width": 500,
"height": 333
},
"medium": {
"ext": ".jpg",
"url": "/uploads/medium_002_10_b20570c2ca.jpg",
"hash": "medium_002_10_b20570c2ca",
"mime": "image/jpeg",
"name": "medium_002_10.jpg",
"path": null,
"size": 37.45,
"width": 750,
"height": 500
},
"thumbnail": {
"ext": ".jpg",
"url": "/uploads/thumbnail_002_10_b20570c2ca.jpg",
"hash": "thumbnail_002_10_b20570c2ca",
"mime": "image/jpeg",
"name": "thumbnail_002_10.jpg",
"path": null,
"size": 6.71,
"width": 234,
"height": 156
}
},
"hash": "002_10_b20570c2ca",
"ext": ".jpg",
"mime": "image/jpeg",
"size": 130.19,
"url": "/uploads/002_10_b20570c2ca.jpg",
"previewUrl": null,
"provider": "local",
"provider_metadata": null,
"created_at": "2021-10-23T18:37:13.658Z",
"updated_at": "2021-10-23T18:37:13.941Z"
}
}
]
Okay, Here's how I solved it:
I was getting the wrong object calling slug on the function when the Strapi relies on the ID
The first step was changing the findOne function to get the slug and not the ID following this video here
https://www.youtube.com/watch?v=gtvXiRqn0ZI
with this piece of code:
const { sanitizeEntity } = require('strapi-utils');
module.exports = {
/**
* Retrieve a record.
*
* #return {Object}
*/
async findOne(ctx) {
const { slug } = ctx.params;
const entity = await strapi.services.restaurant.findOne({ slug });
return sanitizeEntity(entity, { model: strapi.models.restaurant });
},
};
Then I started to get the correct data for the title and description.
On the Nuxt side the v-for was updated to:
v-for='image of gallery.images'
And the image tag:
<img class="w-full h-96 object-cover rounded transition ease-in-out transform hover:-translate-y-1 hover:shadow-xl hover" :src="$config.strapiUrl + image.url" alt="" />`
Thanks to #IAmRoot from Strapi - Discord who helped me on that too.