标签:tde 手动 使用 header import exp http eth express
1. 前端请求(recommend.js);
import axios from ‘axios‘
export function getDiscList() {
const url = ‘/api/getDiscList‘
const data = Object.assign({}, commonParams, {
platform: ‘yqq‘,
hostUin: 0,
sin: 0,
ein: 29,
sortId: 5,
needNewCode: 0,
categoryId: 10000000,
rnd: Math.random(),
format: ‘json‘
})
return axios.get(url, {
params: data
}).then((res) => {
return Promise.resolve(res.data)
})
}
2. 手动代理请求(webpack.dev.conf.js);
var express = require(‘express‘)
var axios = require(‘axios‘)
var app = express()
var apiRoutes = express.Router()
app.use(‘./api‘,apiRoutes)
//在devServer 中添加下面代码
before (app) {
app.get(‘/api/getDiscList‘, function (req, res) {
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)
})
})
}
3. 组建中使用(recommend.vue)
import {getDescList} from ‘api/recommend‘
import {ERR_OK} from ‘api/config‘
export default {
created() {
this._getDiscList()
},
methods: {
_getDiscList() {
getDiscList().then((res) => {
if (res.code === ERR_OK) {
this.discList = res.data.list
console.log(res.data.list)
}
})
},
}
标签:tde 手动 使用 header import exp http eth express
原文地址:https://www.cnblogs.com/jy13638593346/p/9342520.html