我可以在 nuxt.config.js 中访问 nuxt 上下文吗?

     2023-02-22     79

关键词:

【中文标题】我可以在 nuxt.config.js 中访问 nuxt 上下文吗?【英文标题】:Can I access nuxt context in nuxt.config.js? 【发布时间】:2020-07-12 04:42:21 【问题描述】:

我正在使用nuxt-i18n 和@nuxtjs/auth,我想像这样配置auth.redirect 选项来支持i18n:

// nuxt.config.js

export default 
  modules: [
    '@nuxtjs/auth',
    'nuxt-i18n',
    // ...
  ],
  auth: 
    redirect: 
      home: localePath('/dashboard'),
      // ...
    ,
  ,
  // ...
;

通常,就像this.$store一样,我可以通过应用程序实例访问nuxt-i18n提供的localePath函数或context,如this.$localePathapp.localePath。但是怎么在nuxt.config.js文件里面使用呢?

【问题讨论】:

【参考方案1】:

如果 @nuxt/auth 模块存在 i18n 重定向支持问题,我找到了解决方法:https://github.com/nuxt-community/auth-module/issues/1116#issuecomment-824814739。

信用@azrikahar

【讨论】:

如何访问 Nuxt 插件中的 .env 变量?

...uxt.js项目中,我创建了一个名为segment.js的插件,我在nuxt.config.js中注册了它:nuxt.config.jsplugins:[src:"~ 查看详情

nuxt.config.js文件

...e-devcross-env安装cross-env。如果你在非Windows环境下开发,你可以不用安装cross-env,这时需要把start脚本中的cross-env去掉。Nuxt.js让你可以配置在客户端和服务端共享的环境变量。例如(nuxt.config.js):以上配置我们创建一个baseUrl环境变... 查看详情

如何在 Nuxt 的 nuxt.config.js 中导入 mdi 图标模块

】如何在Nuxt的nuxt.config.js中导入mdi图标模块【英文标题】:Howtoimportthemdiiconsmoduleinsidenuxt.config.jsinNuxt【发布时间】:2021-01-2004:20:51【问题描述】:我已经安装了https://materialdesignicons.com/npminstall@mdi/font在nuxt.config.js文件中,我不知... 查看详情

在 Apollo Nuxt 中,如何在方法中访问非默认客户端?

...默认客户端(Shopify)。理想情况下是这样的:在我的nuxt.config.js中,我有这样的Apollo设置:apo 查看详情

如何在 nuxt-i18n 文本中包含链接

...。我已经安装了"nuxt-i18n":"^6.4.1"在我的nuxt.config.js中,我也有闲置modules:[[\'nuxt-i18n\',default 查看详情

在本地 https 上运行 nuxt – nuxt.config.js 的问题

】在本地https上运行nuxt–nuxt.config.js的问题【英文标题】:Runnuxtonhttpslocally–problemwithnuxt.config.js【发布时间】:2019-06-1316:01:18【问题描述】:我正在尝试使用https在本地运行nuxt来测试一些地理定位的东西。(https://nuxtjs.org/,https://n... 查看详情

是否可以在 nuxt.config.js 或通过定义 sass 变量来更改主题默认文本颜色?

】是否可以在nuxt.config.js或通过定义sass变量来更改主题默认文本颜色?【英文标题】:Isitpossibletochangethemedefaulttextcolorinnuxt.config.jsorbydefiningsassvariable?【发布时间】:2020-09-2204:23:10【问题描述】:我有Nuxt/Vuetify应用程序,配置如... 查看详情

使用 jest 测试 nuxt.js 应用程序时访问 `process.env` 属性

...t.js应用程序编写单元测试。但是我的一些组件使用在nuxt.config.js文件中声明的process.env属性。当我运行我的测试时,我收到了 查看详情

Nuxt.js:页面转换

...s【发布时间】:2021-03-2300:08:40【问题描述】:在我的nuxt.config.js中,我添加了loading:\'~/components/LoadingBar.vue\'。部署站点后,我的自定义页面转换工作,但仅当访问的第一个页面与home页面不同时。例如,如果您访问此链接并从那... 查看详情

如何将 nuxt.config.js 中的 .env 值与运行时配置一起使用

...述】:我正在搜索。声明它,在“正常”代码中使用它是可以的。publicRuntimeConfig:URL_API:process.env.URL_API||\'http://localhost:80 查看详情

如何使用 Nuxt.js 仅在一个组件中使用插件?

...站,我只需要在一个组件中导入编辑器,我不想使用nuxt.config.js。这是我正在尝试做的,但它似乎不起作用。//Inside\'~/plugins/vue2-editor\'im 查看详情

如何在 Jest 测试中使用 nuxt 运行时配置变量

...时配置变量的方法时,它会引发undefinedvariableerror。有人可以帮我知道如何在开玩笑测试中使用nuxt运行 查看详情

在整个 Nuxt.js 应用中声明一次 Api 的 URL

...使用CMS来填充我的Nuxt.js应用程序并声明apiURL如下。在nuxt.config.js中,要生成动态路由,我有:constapiUrl=\'http://xxx.xx.xx.xx:xxxx\'generate:routes 查看详情

nuxt.config.js 中的条件属性

】nuxt.config.js中的条件属性【英文标题】:Conditionalattributeinnuxt.config.js【发布时间】:2019-08-1615:13:30【问题描述】:我正在开发一个使用nuxt.js的网站,并且希望有条件地在nuxt.config.js中有一个配置选项:我想更改路由器我运行npmr... 查看详情

nuxt.config.js 在哪里构建模块仅在开发模式下构建?

】nuxt.config.js在哪里构建模块仅在开发模式下构建?【英文标题】:nuxt.config.jswherebuildmodulesbuildonlyindevmode?【发布时间】:2021-03-1700:36:33【问题描述】:源码:github.com/alexpilugin/ap-nuxt-firebase-s-s-r接下来是问题:此Nuxts-s-r应用程序... 查看详情

在客户端使用 NPM 包和 nuxt

...nfig.js中并与npm一起安装。我在/plugins目录中还有一个文件可以导入它们(不确定这是否好用)。这是我遇到麻烦的地方:我 查看详情

从自定义 .js 文件访问应用程序上下文以获取语言环境消息

...构建Vue.js应用程序。我的项目中有axios和vue-i18n插件。nuxt.config.js:exportdefaultmode:\ 查看详情

Nuxt.config.js noscript innerHtml 在浏览器上呈现

】Nuxt.config.jsnoscriptinnerHtml在浏览器上呈现【英文标题】:Nuxt.config.jsnoscriptinnerHtmlrenderingasitonbrowser【发布时间】:2020-09-2710:10:24【问题描述】:IhavedisabledjavascriptfrombrowserAddedinnerhtmlfornoscripttaginnuxt.config.jsExpectedbeh 查看详情