Skip to content

Instantly share code, notes, and snippets.

@thefln
Created November 27, 2017 20:42
Show Gist options
  • Select an option

  • Save thefln/8f5d2b94b504e141d3730b659437f34f to your computer and use it in GitHub Desktop.

Select an option

Save thefln/8f5d2b94b504e141d3730b659437f34f to your computer and use it in GitHub Desktop.
component.vue
// pages/index.vue
<script>
import axios from 'axios'
import SmallProduct from '~/components/SmallProduct.vue'
export default {
components: {SmallProduct},
async asyncData ({env, params}) {
let {data} = await axios.get(`${env.cockpit.apiUrl}/collections/get/Product?token=${env.cockpit.apiToken}`)
let products = await Promise.all(await data.map(async (p) => {
let result = await axios.post(`${env.cockpit.apiUrl}/mediamanager/thumbnails?token=${env.cockpit.apiToken}`, {
images: [p.Image],
w: 300,
h: 300,
options: {
quality: 80,
mode: 'resize'
}
})
p.ThumbUrl = `${env.cockpit.baseUrl}${result.data[p.Image]}`
return p
}))
return {
products
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment