如何解决无法访问nuxt-i18n信息
我正在nuxt中创建一个国际博客。我似乎无法访问导航组件和某些页面上的i18n对象。您能否阐明如何访问它以及为什么我不能访问它?我假设它与生命周期有关,但不确定...
在nuxt-config.js中:
...
modules: [
'nuxt-i18n','@nuxt/content'
],i18n:{
strategy: 'prefix_and_default',defaultLocale: 'en',langDir: 'lang/',lazy: true,locales: [
{
name: '日本語',code: 'ja',iso: 'ja-JP',file: 'ja-JP.js'
},{
name: 'English',code: 'en',iso: 'en-US',file: 'en-US.js'
},],detectBrowserLanguage: {
// If enabled,a cookie is set once a user has been redirected to his
// preferred language to prevent subsequent redirections
// Set to false to redirect every time
useCookie: true,// Set to override the default domain of the cookie. Defaults to host of the site.
cookieDomain: null,// Cookie name
cookieKey: 'i18n_redirected',// Set to always redirect to value stored in the cookie,not just once
alwaysRedirect: false,// If no locale for the browsers locale is a match,use this one as a fallback
}
},...
我试图根据语言引入不同的降价文件,所以我打电话:
export default {
async asyncData({ $content,params}) {
const data = await $content(`${i18n.locale}/data`,params.slug).fetch()
return { data }
},
在内容上我有en/data/...
和ja/data/...
,如果我将其硬编码为en/data/
或ja/data
,它可以工作,但是我得到的是i18n是未定义的错误,我尝试了几次模式,但没有成功。
解决方法
我认为最好在您的代码中使用这种结构
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。