Patrik.S
Patrik.S
Explore posts from servers
NNuxt
Created by Patrik.S on 6/21/2024 in #❓・help
option api - useNuxtApp
Hello, I’m migrating bigger project from nuxt2 to 3 🙈, and I found out that I don’t know how to call plugin in option api. The plugin looks like this:
export default defineNuxtPlugin((nuxtApp) => {
return {
provide: {
hello: () => `Hello`
}
}
})
export default defineNuxtPlugin((nuxtApp) => {
return {
provide: {
hello: () => `Hello`
}
}
})
I know i can get $hello in setup:
const { $hello } = useNuxtApp()
const { $hello } = useNuxtApp()
But the question is how can I get the $hello in option API - I don’t like calling it at every method. At nuxt2 a just call it in method like ‘this.$hello’ and I had full context. Is there any elegant solution for this? Thanks for any advice!
2 replies
NNuxt
Created by Patrik.S on 3/30/2023 in #❓・help
Undefined cookie inside middleware
https://stackblitz.com/edit/nuxt-starter-zctfjj?file=middleware/createContractId.ts Hey, I am trying to resolve the cookie inside middleware. When I set cookie and navigateTo I get undefined cookie after refresh page the cookie is known. I work with something like this:
if (!contractId && process.server) {
const contract: { id: string } = await $fetch('/api/get-contract-id');
// when i got contractId a set it up too cookie
setCookie({ contractId: contract.id });

// after setup cookie i redirect to page vie name
return navigateTo({
name: `online-contractId-first-page`,
query: {
...from.query,
},
params: {
contractId: contract.id,
},
});
}

// after navigate the cookie is undefined, and when i hit f5 its working
console.log(cookie);
if (!cookie) {
throw createError({
message: 'Cookie not exist',
fatal: true,
});
}
if (!contractId && process.server) {
const contract: { id: string } = await $fetch('/api/get-contract-id');
// when i got contractId a set it up too cookie
setCookie({ contractId: contract.id });

// after setup cookie i redirect to page vie name
return navigateTo({
name: `online-contractId-first-page`,
query: {
...from.query,
},
params: {
contractId: contract.id,
},
});
}

// after navigate the cookie is undefined, and when i hit f5 its working
console.log(cookie);
if (!cookie) {
throw createError({
message: 'Cookie not exist',
fatal: true,
});
}
if I try setTimout the navigateTo approx. 300ms then it works any tip what can i do?
3 replies
NNuxt
Created by Patrik.S on 3/16/2023 in #❓・help
Problem after migrating to 3.3.1 from (3)
I getting errors 1. 500 [vite-node] [plugin:vite:vue] [VITE_ERROR] /pages/chyba-bankid-chybne-udaje.vue?macro=true I found similar problem in vite repo, but didnt help. Has anyone encountered this problem? 2. When i tried build npx nuxi build
Nuxi 3.3.1
ℹ Building client... 09:53:14ℹ vite v4.1.4 building for development... 09:53:14ℹ ✓ 22 modules transformed.
09:53:14 ERROR [vite:vue] Cannot set properties of undefined (setting 'id') 09:53:14
file: path-to-project/node_modules/nuxt/dist/app/components/nuxt-root.vue

ERROR Cannot set properties of undefined (setting 'id') 09:53:14

at createDescriptor (node_modules/nuxt/node_modules/@vitejs/plugin-vue/dist/index.mjs:69:17)
at transformMain (node_modules/nuxt/node_modules/@vitejs/plugin-vue/dist/index.mjs:2206:34)
at Object.transform (node_modules/nuxt/node_modules/@vitejs/plugin-vue/dist/index.mjs:2698:16)
at node_modules/rollup/dist/es/shared/node-entry.js:24343:40
Nuxi 3.3.1
ℹ Building client... 09:53:14ℹ vite v4.1.4 building for development... 09:53:14ℹ ✓ 22 modules transformed.
09:53:14 ERROR [vite:vue] Cannot set properties of undefined (setting 'id') 09:53:14
file: path-to-project/node_modules/nuxt/dist/app/components/nuxt-root.vue

ERROR Cannot set properties of undefined (setting 'id') 09:53:14

at createDescriptor (node_modules/nuxt/node_modules/@vitejs/plugin-vue/dist/index.mjs:69:17)
at transformMain (node_modules/nuxt/node_modules/@vitejs/plugin-vue/dist/index.mjs:2206:34)
at Object.transform (node_modules/nuxt/node_modules/@vitejs/plugin-vue/dist/index.mjs:2698:16)
at node_modules/rollup/dist/es/shared/node-entry.js:24343:40
Does anyone have a clue how I can fix this or where the problem is. Thanks a lot
1 replies