image
image copied to clipboard
chore: upgrade components to composition API
This PR upgrades the NuxtImg
and NuxtPicture
components to use the Composition API, and exposes a new useImage
composable with the same behavior of the $img
utility.
Other changes:
- the
nuxt-img
component now supportspreload
Deploy Preview for nuxt-image-v1 canceled.
Name | Link |
---|---|
Latest commit | db7f982a8bdef1186edca4df465e555a48159963 |
Latest deploy log | https://app.netlify.com/sites/nuxt-image-v1/deploys/63138640780710000a18ac48 |
Would be nice adding the example directly to docs. Don't know if that should go to a separate PR? :)
<script lang="ts" setup>
const { generate } = useImage()
const bg = computed(() => {
const imgUrl = generate('/images/colors.jpg', {
width: 300,
height: 300,
quality: 80
})
return `url('${imgUrl}')`
})
</script>```
@AndersNielsen85 I changed back usage to $img = useImage()
($img
is a function with attached props)
Thanks for helping on this. Nice changes ❤️
@pi0 no problem, happy to help.