使用axios的调用方法,proxyTable解决开发环境跨域:
打开 config 下的 index.js
dev 这样写jiukeyi
dev: { // Paths assetsSubDirectory: 'static', assetsPublicPath: '/', proxyTable: { '/api':{ target: 'http://bowensi.xiaoniren.cn/restapi/',//设置你调用的接口域名和端口号 别忘了加http changeOrigin: true, pathRewrite:{ '^/api': '/' //这里理解成用‘/api’代替target里面的地址,后面组件中我们掉接口时直接用api代替 // 比如我要调用'http://40.00.100.100:3002/user/add',直接写‘/api/user/add’即可 } } },api使用 :直接使用代替接口域名
this.$http.get('/api/default/hot-article.html',{params: {category_id: 7}}) .then((response) => { that.xinde=response.data.data; });