新建vue项目后
npm install vue-resource(听说已经停更)
npm install axios
main.js
import axios from 'axios'
Vue.prototype.axios = axios;
confing文件下 index.js
proxyTable: {
'/type': {
target: 'http://******.com',//你的链接
changeOrigin: true,
pathRewrite: {
'^/type': ''
}
}
},
页面.vue
methods:{
ajx: function() {
this.$http.get("/type/api/dict/getDict",{},{
headers: {},
emulateJSON: true
}
)
.then(function(res) {
console.log(res);
},function(error) {
console.log(error);
}
);
},
test:function(){
this.axios({url:'/type/api/dict/getDict',method: 'GET',})
.then(function (res) {
console.log("12");
console.log(res);
},function (error) {
console.log("请求失败!!!")
});
}
},
mounted(){
this.ajx();
this.test();
}
vue-resource 获取的数据
axios