问题标签 [nuxt-i18n]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
seo - nuxt meta robots 在生产模式下设置为 noindex
我不明白为什么我的应用程序仅在生产模式下将元机器人设置为 noindex ?这是我的 nuxt.config
我什至在布局 /default.vue 中设置了元数据以防万一,但还是一样。这让我发疯!在开发模式下完全没问题。为什么会有人想要没有索引和开发或暂存的生产?这是荒谬的。
nuxt.js - 如何访问 asyncData 中的模板?
我想在 asyncData 中访问 this.$el。我使用数据库来存储翻译。我想获取当前页面上使用的翻译列表。然后我会向服务器发送一个请求来接收它们。之后,我将合并它。
怎么做 ?
nuxt.js - Nuxt context.route 未在 asyncData() 中更新
我正在使用asyncData
slug 来获取页面的当前数据,以在我的 API (Strapi) 中查找数据。这适用于新页面加载,但在导航到另一种语言 (nuxt-i18n) 时会失败。当导航到另一种语言时,调用了 asyncData 但由于某种原因尚未更新路由,因此 slug 匹配失败。手动刷新页面会更新路由,然后 slug 匹配。
我正在使用的语言切换器如下所示:
知道为什么route.params.slug
(或通常的路线)在客户端导航到不同语言后没有更新吗?
编辑:我目前的解决方法是不使用NuxtLink
组件,而是使用普通的锚标签,如下所示:
这会重新加载页面并正确加载asyncData
依赖于将页面与 API 匹配的路由参数。
vue.js - nuxt-i18n 更改语言 && 路由其他页面
如何在 nuxt-i18n 下同时使用以下 nuxt-links:
<nuxt-link :to="switchLocalePath('en')">EN</nuxt-link>
和
<nuxt-link :to="localePath('/about')">About</nuxt-link>
因此,当我更改语言时,它会自动将我丢到关于页面。
vue.js - How to correctly use vuex when migrating from vue-i18n to nuxt-i18n?
I am trying to migrate from vue-i18n to nuxt-i18n. So far, while using vue-i18n, I have managed the store myself. At the moment, I am stuck at the adaptation of my project, at the point of using nuxt-i18n with vuex. In my opinion, the documentation of nuxt-i18n is lacking essential information here.
My nuxt-i18n config looks as follows:
My store, which was introduced before using nuxt-i18n, looks like this:
The messages/translations are already loaded correctly, but it seems to me that I am using two stores (i18n and nuxt-i18n) beside each other at the moment, which somehow magical intersect with each other!? I don't understand, how I can merge my previous i18n store with the nuxt-i18n store so that in the end, I have only one single store for locale
, locales
, and for my functions. I also don't understand, if I even have to define locale
and locales
in the store, or if this is done automatically by nuxt-i18n, and thus I only have to find a way to define my functions.
Maybe someone can enlighten me, how to migrate my store from vue-i18n to nuxt-i18n correctly, and how nuxt-i18n and vuex are working together.
javascript - 如何在 Nuxt 中访问 .js 文件中的环境变量
我有以下文件:
问题是它process.env.SUB_DOMAIN
似乎是未定义的/services/i18n/index.js
,尽管它是设置的,因为同一个变量不是未定义的nuxt.config.js
。我知道 nuxt 公开了publicRuntimeConfig
as的值$config
,但是$config
在/services/i18n/index.js
. 如果我移动locales
到,它可能会起作用nuxt.config.js
,但我不想这样做,因为它会恶化配置文件的可读性。
所以我的问题是最好的方法是让子域里面/services/i18n/index.js
。
nuxt.js - Vuex-Persistedstate 在重新加载时运行突变
我正在使用 Nuxt 2、Vue 2、Vuex 3、Vuetify 2、vuex-persistedstate 4 和 nuxt-i18n 6。
我将此插件设置为保留包含RTL 状态和语言代码的 Vuex 状态:
plugins/persistedState.client.js
:
另外,我编写了一些突变来将此设置保存在状态中并将主题应用于 vuetify:
store/app/index.js
:
- 通过调用
setLangCode
突变,语言将被设置为给定的语言并将其保存在状态中 - 通过调用
setRTL
vuetify 的 rtl 方向将正确设置并将其保存在状态
问题是页面重载时 vuex-persistedstate 会从本地存储中恢复 vuex 状态,但设置 vuetify 设置的 mutaion 不会被调用,因此 vuetify 将保持在磨损方向。
此外,nuxt-i18n 将检测来自 url而不是来自状态的语言代码,并以此为基础翻译页面。
nuxt-i18n - 如何使用 JSON 文件中的字符串检索 nuxt 中的本地化字符串?
我有一个包含多种语言的网站。菜单需要在某些组件中填充,因此为避免重复,我编写了一个 JSON 文件,其中包含一组 slugs 和名称。
我导入 JSON 文件,并在模板内填充菜单:
它可以工作,但由于我的菜单必须被转换,我需要使用link.name值传递给 $t(),以便检索其本地化值。如果我用“{{ $t('link.name') }} 替换“{{ link.name }}”,即使我已经准备好调用本地化字符串,HTML 输出也是 link.name。我真的没有'不知道如何使用 JSON 数组中的字符串并将其传递给 {{ $t() }} 函数。非常欢迎任何帮助!
vue.js - Vuejs如何在不退出该组件的情况下更改组件中的URL
我是 VueJs 的新手。
我正在与 wizaplace 合作。实际上,我有一条名为 /breweries/:id 的路线,它采用 wizaplace 公司的 id(API 只需要一个 ID 即可获取公司)来调用 wizaplace API 并获取公司信息。
在这些数据中,我想在 url 中显示一个 slug 而不是 ID。
请问我怎么能做到这一点?
我是否应该做一个“桥接”组件,通过其 id 获取公司的数据并将 id 和 slug 推送到另一个端组件,该组件将再次获得公司的 ID,但在 URL 中显示 $route.params.slug ?
我知道这不是一种正确的工作方式,但这是我创业的需要。
谢谢你的帮助 !
vue.js - 忽略 nuxt-i18n 模块中特定路由的语言环境前缀
对于所有页面,我需要语言环境前缀。但是对于个人资料页面,我想忽略它。
我在 nuxt-i18n 配置选项中选择前缀策略。有什么解决办法吗?