Open MirzaeiDev opened 4 years ago
Try to import vue-product-zoomer as a Nuxt plugin.
Create the file ~/plugins/vue-product-zoomer.js :
import Vue from 'vue'
import ProductZoomer from 'vue-product-zoomer'
Vue.use(ProductZoomer)
And then bind it in nuxt.config.js :
export default {
// ...
plugins: [
'~/plugins/axios.js',
'~/plugins/vue-product-zoomer.js'
],
// ...
}
Finally, use the component wherever you want in a .vue template
<product-zoomer
:base-images="images"
:base-zoomer-options="zoomerOptions"
/>
I tried importing it as a nuxt plugin.
// ~/plugins/product-zoomer.js
import Vue from 'vue'
import ProductZoomer from 'vue-product-zoomer'
Vue.use(ProductZoomer)
// nuxt.config.js
...
plugins: [
...
{ src: '~/plugins/product-zoomer.js', mode: 'client' },
]
...
// Using it as:
<template>
<client-only>
<ProductZoomer :base-images="images" :base-zoomer-options="zoomerOptions" />
</client-only>
</template>
The issue is it doesn't work on initial load of the page.
This module only run the detail page. That's why I loaded this module dynamically on the detail page.
// ~/plugins/product-zoomer.js
import Vue from 'vue'
import ProductZoomer from 'vue-product-zoomer'
Vue.use(ProductZoomer)
// Trigger for mounted
data() {
return {
isMounted: false,
}
}
// Dynamic load when mounted
async mounted() {
await Promise.all([import('@/plugins/vue-product-zoomer.js')])
this.isMounted = true
}
<section v-if="isMounted" class="detail-gallery">
<ProductZoomer :base-images="images" :base-zoomer-options="zoomerOptions" />
</section>```
It worked like this but sometimes can't get the width value
So now what can I do to not be global? I found my answer on this site.
I use a single component on my project but I have an error. pls, help me with this error. so I use this for my code.
if we run project
we can see error
Well look at this interesting point if I come to pick up the brackets`
and if I refresh my page can see this error
pleas help meeeeeeeeeeeeee. what can I do ????????????????????????????