Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for nuxt 3 #715

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions nuxt3/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineNuxtModule, addPlugin } from '@nuxt/kit';

const __dirname = dirname(fileURLToPath(import.meta.url));

/*
Directives will be ignored by Vue in SSR. However the v-scroll-to directive
needs to exist in the SSR context or an error will occur: `Cannot read
properties of undefined (reading 'getSSRProps')`. Make sure to enable this
plugin for SSR and Vue will just ignore the directive when rendered server side.
Remove `.client` from the filename and remove `mode: 'client'` inside
nuxt.config.js

https://vuejs.org/guide/scaling-up/ssr.html#custom-directives
https://github.com/nuxt/framework/issues/3154
https://github.com/nuxt/framework/issues/6570
*/


export default defineNuxtModule({
meta: {
name: 'vue-scrollto',
configKey: 'scrollto',
compatibility: {
nuxt: '^3.0.0-rc.11',
},
},
defaults: {},
hooks: {},
setup(options, nuxt) {
addPlugin({
mode: 'all',
src: resolve(__dirname, 'plugin.js'),
// fileName: 'vue-scrollto.js',
// options,
});
},
});
10 changes: 10 additions & 0 deletions nuxt3/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import VueScrollTo from 'vue-scrollto';

export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.use(VueScrollTo);
return {
provide: {
scrollTo: VueScrollTo.scrollTo,
},
};
});
Loading