Open gravitano opened 2 years ago
I've also tried it but got no luck. Seems this plugin is not supported for SSR. Hope @bennyxguo will consider to make it support SSR 😁
I think this plugin can support SSR via client-only plugin in Nuxt 3. For example, in my case just rename ./plugins/vue-scroll-spy.ts
to ./plugins/vue-scroll-spy.client.ts
.
Reference: https://nuxt.com/docs/guide/directory-structure/plugins
What I did on my Vue/Vite project was installing https://www.npmjs.com/package/vite-plugin-iso-import. Then I defined a plugin that registers the scroll-spy plugin:
import {registerScrollSpy} from 'vue3-scroll-spy?client';
export default {
install(app, options: {ssr: boolean}) {
// Fixes: Cannot read properties of undefined (reading 'getSSRProps')
if (options.ssr) {
app.directive('scroll-spy', {})
app.directive('scroll-spy-active', {})
app.directive('scroll-spy-link', {})
}
// Only import when non-SSR
if (typeof registerScrollSpy !== 'undefined') {
registerScrollSpy(app, options);
}
},
}
I think this plugin can support SSR via client-only plugin in Nuxt 3. For example, in my case just rename
./plugins/vue-scroll-spy.ts
to./plugins/vue-scroll-spy.client.ts
.Reference: https://nuxt.com/docs/guide/directory-structure/plugins
I've tried this one but still not working
What I did on my Vue/Vite project was installing https://www.npmjs.com/package/vite-plugin-iso-import. Then I defined a plugin that registers the scroll-spy plugin:
import {registerScrollSpy} from 'vue3-scroll-spy?client'; export default { install(app, options: {ssr: boolean}) { // Fixes: Cannot read properties of undefined (reading 'getSSRProps') if (options.ssr) { app.directive('scroll-spy', {}) app.directive('scroll-spy-active', {}) app.directive('scroll-spy-link', {}) } // Only import when non-SSR if (typeof registerScrollSpy !== 'undefined') { registerScrollSpy(app, options); } }, }
I'll try this one. Thank you!
Hello. Thank you for your great work!
Is this package support SSR? I tried install on nuxt 3 but had errors:
Here's code for the plugin:
Thank you