1.修改config-->index.js-->修改里面的proxytable:
proxyTable: { '/api': { //目标:指向的网络地址 target: 'http://api.douban.com/v2', //webpack的属性,映射一个host changeOrigin: true, pathRewrite: { '^/api': '' } } },
2.在main.js里面配置Host
import Axios from "axios" Vue.prototype.HOST = '/api' Vue.prototype.$axios = Axios
3.组件里面发送请求:
created(){ var url = this.HOST+"/movie/top250"; this.$axios.get(url,{ params:{ count:10, start:0 } }) .then(res => { this.filterData(res.data); }) .catch(error => { console.log(error) }) }