vue 2.0后端代理接口

1.找到webpack-dev-config.js

 

在头部引入以下文件

var express = require('express')
var axios = require('axios')
var app = express()
var apiRoutes = express.Router()
app.use('/api', apiRoutes)

然后找到devSever

before(app) {
      app.get('/api/getDiscList', function (req, res) {
        console.log(11)
       
        var url = 'https://c.y.qq.com/splcloud/fcgi-bin/fcg_get_diss_by_tag.fcg'
        axios.get(url, {
          headers: {
            referer: 'https://c.y.qq.com/',
            host: 'c.y.qq.com'
          },
          params: req.query
        }).then((response) => {
          res.json(response.data)
        }).catch((e) => {
          console.log(e)
        })
      })
    },

重启项目  就ok

posted @ 2019-08-08 14:30  zhupan  阅读(2295)  评论(0编辑  收藏  举报