PanJiaChen / vue-element-admin

:tada: A magical vue admin https://panjiachen.github.io/vue-element-admin
MIT License
87.07k stars 30.39k forks source link

npm run build:prod打包,通过Nginx代理后访问java后台,在登陆页面不能跳转。 #4183

Open abangv opened 11 months ago

abangv commented 11 months ago

mock部分已处理。请求和返回值正常,不能跳转。页面提示error。(无其他报错或说找不到其他错误) vue.config.js //空白页面问题 // .plugin('ScriptExtHtmlWebpackPlugin') // .after('html') // .use('script-ext-html-webpack-plugin', [{ // // runtime must same as runtimeChunk name. default is runtime // inline: /runtime..*.js$/ // }]) // .end() //取消请求mock数据 // , before: require('./mock/mock-server.js') main.js //取消请求mock数据 // if (process.env.NODE_ENV === 'production') { // const { mockXHR } = require('../mock') // mockXHR() // }

nginx配置: location / { root html; index index.html index.htm; try_files $uri $uri/ /index.html; } location ^~/prod-api { proxy_pass http://localhost:8080/; } login和getInfo请求返回值均正常。

nginx中mock下正常跳转,(放开以下注释) main.js:

, before: require('./mock/mock-server.js')

if (process.env.NODE_ENV === 'production') { const { mockXHR } = require('../mock') mockXHR() }

abangv commented 11 months ago

image image

abangv commented 11 months ago

已解决:问题的关键在于token的读取。因为存储在头信息中的token键名不一样,所以导致的错误。 大概思路:需要处理request.js 中geiInfo()中的响应的token信息。建议统一键的名称,如:“X-Token”,"My-Token",其次const {}(解析表达式不能获取嵌套的token值),token需要从response.data中获取。

doruk5 commented 6 months ago

sahte hata ) vue.config.js //空白页面问题 // .plugin('ScriptExtHtmlWebpackPlugin') // .after('html') // .use('script-ext-html-webpack-plugin', [{ // // runtimeruntimeChunk adıyla aynı olmalıdır. varsayılan runtime // satır içi: /runtime..*. js$/ // }]) // .end() //取消请求mock数据 // , before: require('./mock/mock-server.js') main.js //取消请求mock数据 // if (process.env.NODE_ENV === 'üretim') { // const { maketXHR } = require('../mock') // maketXHR() // }

nginx: konum / { kök html; indeks indeksi.html indeks.htm; try_files $uri $uri/ /index.html; } konum ^~/prod-api { proxy_pass http://localhost:8080/ ; } giriş yapın ve getInfo'yu ziyaret edin.

nginx için sahte bir örnek main.js:

, önce: require('./mock/mock-server.js')

if (process.env.NODE_ENV === 'üretim') { const { maketXHR } = require('../mock') maketXHR() }