You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently working on vue3 with composition Api and Vite (cf vitesse https://github.com/antfu/vitesse/tree/main), and its working well for me.
Here's my implementation:
src/main.ts:
import{ViteSSG}from'vite-ssg'import{setupLayouts}from'virtual:generated-layouts'import*ascookiesfrom'vue-cookies'// import Previewer from 'virtual:vue-component-preview'importAppfrom'./App.vue'importgeneratedRoutesfrom'~pages'import'./styles/main.scss'constroutes=setupLayouts(generatedRoutes)// https://github.com/antfu/vite-ssgexportconstcreateApp=ViteSSG(App,{ routes,base: import.meta.env.BASE_URL},(ctx)=>{ctx.app.use(cookies)},)
src/composables/cookies.ts:
import{inject}from'vue'importtype{VueCookies}from'vue-cookies'exportfunctionuseCookies(): VueCookies{const$cookies=inject<VueCookies>('$cookies')// For js, use const $cookies = inject('$cookies')return$cookiesasVueCookies}
Activity
julisch94 commentedon Oct 10, 2023
Just to confirm, have you imported
inject
?Kharente-Deuh commentedon Oct 26, 2023
I'm currently working on
vue3
withcomposition Api
andVite
(cf vitesse https://github.com/antfu/vitesse/tree/main), and its working well for me.Here's my implementation:
src/main.ts:
src/composables/cookies.ts:
And then, use it like that:
src/App.vue: