先安装!
npm install axios
然后!
npm install --save axios vue-axios
axios.defaults.baseURL为统一请求地址的前缀
import Vue from 'vue'
import axios from 'axios'
axios.defaults.baseURL = "http://localhost:9090/"; // 设置axios的基础请求路径
axios.defaults.timeout = 2000; // 设置axios的请求时间
axios.defaults.withCredentials = true; // 设置axios的请求时间
// axios.interceptors.request.use(function (config) {
// // console.log(config);
// return config;
// })
axios.loadData = async function (url) {
const resp = await axios.get(url);
return resp.data;
}
Vue.prototype.$http = axios;// 将axios添加到 Vue的原型,这样一切vue实例都可以使用该对象
import './http';
this.$http.get('blog/queryBlogByPage?title=' + this.title + '&page=' + this.page + '&rows=' + this.rows)
.then(response => (
)).catch(function (error) { // 请求失败处理
console.log(error);
});
//定义一个请求参数的对象,通过结构表达式来获取brand当中的属性
const { ...params } = this.data;//data为表单数据
this.$http({
method: 'post',
url: '/item/car/save',
data: params
}).then(() => {
// 关闭窗口
this.$emit("close");
this.$message.success("保存成功!");
}).catch(() => {
this.$message.error("保存失败!");
});
const { ...params } = this.data;//data为表单数据
this.$http({
method: 'put'
url: '/item/car/save',
data: params
}).then(() => {
}).catch(() => {
});
this.$http.delete('blog/queryBlogByPage?title=' + this.title + '&page=' + this.page + '&rows=' + this.rows)
.then(response => (
)).catch(function (error) { // 请求失败处理
console.log(error);
});
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://code100.blog.csdn.net/article/details/123302546
内容来源于网络,如有侵权,请联系作者删除!