vue-cli配置proxyTable 跨域请求

本地express服务启动端口3000, vue-cli项目启动端口8080, 当前端用户提交登陆信息到后端,
便产生跨域,能够配置 proxyTable 解决跨域问题
一: 进入vue-cli项目下的config/index.js 文件, 添加前端

proxyTable: {
  '/api': {
    target: 'http://xxxxxx.com', // 接口的域名
    // secure: false,  // 若是是https接口,须要配置这个参数
    changeOrigin: true, // 若是接口跨域,须要进行这个参数配置
    pathRewrite: {
      '^/api': ''
    }
  }
},

此处的target 设为 'http://localhost:3000/'

二: 在前端发送请求页面,设置请求urlvue

this.$axios.post('/api/checklogin',{
        username:that.ruleForm.username,
        password:that.ruleForm.password
      })

三 启动本地node服务,启动vue项目,发送请求数据,控制台查看,获取数据成功则配置正确node

相关文章
相关标签/搜索