Comments (4)
If I use addTemplate to set a config file to the user directory, how should I write it? Are there any simple examples?
and i have read #20933 #18762
Still no solution found
from nuxt.js.
That is intended as runtimeConfig (and the whole nuxt config) should be serializable
Check e.g. how nuxt-graphql-client adds templates
from nuxt.js.
I think I have found the answer: Use addPluginTemplate to provide settings to nuxtapp
import { defineNuxtPlugin } from '#imports'
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.provide("auth", {
baseURL: '<%= options.baseURL %>',
<% if (options.http) { %>
http: {
<% if (options.http.handlers) { %>
handlers:{
<% if (options.http.handlers['401']) { %>
401: <%= options.http.handlers['401'] %>
<% } %>
}
<% } %>
}
<% } %>
})
})
addPluginTemplate({
filename: name,
src: resolve(`../runtime/templates`, tempalte),
options: {
...options,
},
})
<template>
<div>Nuxt module playground!</div>
</template>
<script setup lang="ts">
const { $auth } = useNuxtApp()
console.log($auth)
$auth.http.handlers['401']('yahahahah')
</script>
Then I can call the function configured from nuxt.config
from nuxt.js.
But I don't think this is the best way to do it?
from nuxt.js.
Related Issues (20)
- String vs object errors with `createError` and accessing server-thrown errors on client
- Tailwind css issue related to CSS specificity on dev server HOT 1
- keep alive caches are destroyed when visit keep alive excluded page HOT 2
- The package generated under the .output/server/node_modules file is a hyperlink. HOT 2
- 'text/html' is not a valid JavaScript MIME type. HOT 2
- This module cannot be imported in the Vue part of your app. [importing @nuxt/kit from app.vue] causing page to not work HOT 5
- If a component uses empty data in `useFetch`, then `clearError` will be invalidated HOT 2
- Cache control header missing in response headers (while using nitro.publicAssets) HOT 7
- [nuxt] [request error] [unhandled] [500] _fetch is not a function HOT 3
- feat: support passing options to `TypedRouterOptions` when using `experimental.typedPages` HOT 3
- Dynamic layouts HOT 4
- Previous route info HOT 2
- Imported CSS files not correctly injected in circumstances involving lazy-loaded components HOT 1
- Nuxt 3 Dev build time is very slow in WSL 2 Linux Ubuntu ~ ranging up to 30 seconds just to refresh changes HOT 3
- Warning during nuxt generate - cache-driver.js is imported by "virtual:#internal/nitro/virtual/storage", but could not be resolved HOT 1
- "Error: Unable to find component 'path to the component' in the directory 'path to the directory'. The error message 'Cannot read property 'length' of undefined' indicates that there is a bug with nested folder of components. HOT 2
- Betterstack plugin HOT 1
- Server Components missing parent's scoped styles HOT 1
- It is impossible to prevent the display of a 404 error in the browser console HOT 1
- Transitions with comments in pages creates warning + failed to render next route HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nuxt.js.