Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

打包后默认读取的语言不是cookie中存储的语言,导致国际化失败 #3212

Open
liuyeshennai opened this issue May 28, 2020 · 3 comments

Comments

@liuyeshennai
Copy link

liuyeshennai commented May 28, 2020

问题描述

  1. npm run build:prod 打包后放入服务器(我就放Tomcat里了),只改了一个变量vue.config.js中的publicPath: './'

  2. 然后访问应用:localhost:8080/demo/index.html

  3. 登录页并不能显示国际化的内容,而是显示国际化的key

  4. 检查发现问题出在国际化中的getLanguage()方法中:
    const chooseLanguage = Cookies.get('language')

已确认cookie中存储的是zh,或者en ,因为以前访问过。
但是这个方法读取出来的是zh-CN
而系统国际化没有zh-CN这个匹配项,所以导致国际化失败。

目前在getLanguage()添加如下代码解决:
image

国际化失败如图

image

问题出在哪里呢?

   虽然暂时解决,但是没能想明白为何cookie存储了language,但是读取出来的却不一样。
@tom1jack
Copy link

请问你在哪里找到的?我怎么没在login文件夹下的index找到切换语言的图标。

@liuyeshennai
Copy link
Author

请问你在哪里找到的?我怎么没在login文件夹下的index找到切换语言的图标。

因为是引入的组件额:import LangSelect from '@/components/LangSelect'

@PanJiaChen
Copy link
Owner

你打开调试工具看一下 cookie里面到底是什么不就好了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants