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

本地登录报错405 #2866

Closed
pleasecallmeleifeng opened this issue Dec 19, 2019 · 24 comments
Closed

本地登录报错405 #2866

pleasecallmeleifeng opened this issue Dec 19, 2019 · 24 comments

Comments

@pleasecallmeleifeng
Copy link

2019-12-19 14:00:00 pull 的代码

在成功 npm run dev后,登录报错,提示405

image

@WeiJianQiang
Copy link

同样是碰到了这个问题,很无奈

@Tit1e
Copy link

Tit1e commented Dec 19, 2019

main.js 中有这样一个判断

if (process.env.NODE_ENV === 'development') {
  mockXHR()
}

这个判断是生产环境启用 mock,把 production 改为 development 就行了

@iwusong
Copy link

iwusong commented Dec 19, 2019

@Tit1e 文档里不是说改成mock-server了吗 ,你这不又回之前的了吗

@Tit1e
Copy link

Tit1e commented Dec 19, 2019

@RUYTzzZ 发现了,正在找其他解决方案,请问你找到报错原因了吗

@iwusong
Copy link

iwusong commented Dec 19, 2019

@Tit1e 我觉得是mock-server没起作用, 直接在浏览器里面打开接口被重定向到登录页了。 感觉是mock没拦截成,被webpack起的服务拦截了然后又被路由守卫定向到登录了

@Tit1e
Copy link

Tit1e commented Dec 19, 2019

@RUYTzzZ 我发现 get 请求没问题,但 post 就有问题

@iwusong
Copy link

iwusong commented Dec 19, 2019

@Tit1e get 没问题吗 能不能在浏览器中直接打开 我都找不到mock-serve 接口 的地址, 你get测试的是哪一个

@16GRANDE
Copy link

有大佬找到问题在哪了吗,vue-admin-template也是这样

@Tit1e
Copy link

Tit1e commented Dec 19, 2019

@RUYTzzZ 我把登出的接口改为 get 后就可以了,post 就不行,后来我把目录删了重新拉了下就正常了😓

@iwusong
Copy link

iwusong commented Dec 20, 2019

我找到问题了 是node_modules的问题 我把新项目的node_modules 删了 软链接到之前的项目 正常运行 ,但是 重新 npm i 还是405 ,而且之前的项目 九月份的 重新npm i 后也405。
可能 最近的npm 有点问题 。 不是项目的问题

@ynwshy
Copy link

ynwshy commented Dec 20, 2019

@RUYTzzZ 我也是把上次clone的项目跑起来没问题,把node_modules复制到新项目下就可以用 ,对比了下 package-lock.json 不同。复制package-lock.json过来新项目 npm i 也没问题了 。 有没有完美解决问题的方法?

@iwusong
Copy link

iwusong commented Dec 20, 2019

@ynwshy 可能是网络环境的问题 ,清除缓存尝试一下代理到其他网络

@blaunicorn
Copy link

一样的疑问,现在只能注释掉,有更好的方法吗?

@roblues
Copy link
Contributor

roblues commented Dec 21, 2019

这个问题的原因是header里面有自定义Token,发送post时会自动把简单请求变为了复杂请求。
对于复杂请求,异常请求会变成两次请求,首先向服务器发送一个方法为option的请求,服务器在头部回复可以接受的方法。
这里的devServer服务器,回复了不接收post。然后就405了。

@roblues
Copy link
Contributor

roblues commented Dec 21, 2019

收回前一条,还是main.js中,dev模式下没有启动mock的原因。
if (process.env.NODE_ENV === 'development') {
mockXHR()
}
这个判断是生产环境启用 mock,把 production 改为 development 就行了

@iwusong
Copy link

iwusong commented Dec 21, 2019

@roblues emm 建议看一下文档为什么没启用mock https://panjiachen.github.io/vue-element-admin-site/zh/guide/essentials/mock-api.html#mockjs 这个问题只是部分人出现的,有的人是正常的

@cccjt
Copy link

cccjt commented Dec 23, 2019

有人解决了吗?

@alikrc
Copy link

alikrc commented Dec 24, 2019

navigate to src > main.js
find this line
if (process.env.NODE_ENV === 'production') {

change env to 'development'

if (process.env.NODE_ENV === 'development') {

@AnnPhoenix
Copy link

@ynwshy

可以看下您的package-lock.json吗

@pleasecallmeleifeng
Copy link
Author

解决办法:
navigate to src > main.js
find this line
if (process.env.NODE_ENV === 'production') {

change env to 'development'

if (process.env.NODE_ENV === 'development') {

@meizhuhanxiang
Copy link

能非常明确是npm依赖的问题,同样的代码我重新npm install就会出现这个问题,用之前的包就没有这个问题

@chengxuan12
Copy link

没有用proxy代理,直接调用本地的mock数据。get方法好的,post方法405。

after: require('./mock/mock-server.js') 钩子改为
before: require('./mock/mock-server.js')

与这边的login 代理场景不同,仅供参考

@PanJiaChen
Copy link
Owner

#2929

重新拉取最新代码已修复。

@chengxuan12
Copy link

#2929

重新拉取最新代码已修复。

  before: () => {
    if (typeof this.options.before === 'function') {
      this.setupBeforeFeature();
    }
  },
  middleware: () => {
    // include our middleware to ensure
    // it is able to handle '/index.html' request after redirect
    this.setupMiddleware();
  },
  after: () => {
    if (typeof this.options.after === 'function') {
      this.setupAfterFeature();
    }
  }

试着在 before,after里添加路由。是 middleware 层,代理等中间件影响的么?

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