Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

请求的路径为http://106.14.175.81/oauth/token
vue.config.js配置

module.exports = {
  // local Laravel server address for api proxy
  devServer: {
    proxy: {
      '/api': {
        target: 'http://106.14.175.81',
        changeOrigin: true,
      }
    }
  },
  
  // outputDir should be Laravel public dir
  outputDir: '../../../public/',
  publicPath: '/',

  // for production we use blade template file
  indexPath: process.env.NODE_ENV === 'production'
    ? '../resources/views/icustomer.blade.php'
    : 'index.html',
}

代码是放于php框架里,下面那一部分为配合框架的配置

request.js配置

import axios from 'axios'
const request = axios.create({
  baseURL: '', // 基础路径
  withCredentials: true // 表示请求可以携带cookie
})
export default request

请求配置

import request from '../util/request'
export const getToken = data => {
  return request({
    method: 'post',
    url: 'oauth/token',
    data: data
  })
}

使用

 const arr = {
        grant_type: 'password',
        client_id: '1',
        client_secret: '7VTqL26ZqDLsCuT1PtSiwuol5BrYB5yZ3GCRHwQW',
        username: this.form.username,
        password: this.form.password,
        scope: ''
      }
      const data = await getToken(arr)

报错
image.png
文件路径
image.png

哪位大神能帮我解答下


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.6k views
Welcome To Ask or Share your Answers For Others

1 Answer

修改两个地方

proxy: {
      '/api': {
        target: 'http://106.14.175.81',
        changeOrigin: true,
        pathRewrite: {'^/api' : ''}
      }
    }

const request = axios.create({
  baseURL: '/api/', // 基础路径
  withCredentials: true // 表示请求可以携带cookie
})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share
...