Vue Elememt 链接后端

get:

//async 标记为异步请求

// get 直接获取路径并

axios.get(`api/user/selectUserAll`,{

params:{

"tiaoshu":this.tiaoshu,

"pageSize":this.currentPage,

}

})

.then((res) => {

console.log(res)

this.tableData = res.data.userList;

this.maxPage = res.data.maxPage;

});

}

post:

// 先设定传入参数

let params = {

id: this.form.id,

name: this.form.name,

price: this.form.price,

multipartFile: this.form.imgFile,

};

let config = {

// 添加请求头

headers: {

"Content-Type": "multipart/form-data",

},

};

//创建对象

const data = new FormData();

// 加入数据

for (let k in params) {

data.append(k, params[k]);

}

console.log(params);

// 发送异步post

this.request({

method: "post",

url: `api/food/addFood`,

data,

config,

})

// 添加成功!

.then(function (res) {

if (res.data) {

window.alert("添加成功!");

}

});

相关推荐
10年前端老司机2 小时前
10道js经典面试题助你找到好工作
前端·javascript
小小小小宇7 小时前
TS泛型笔记
前端
小小小小宇7 小时前
前端canvas手动实现复杂动画示例
前端
codingandsleeping7 小时前
重读《你不知道的JavaScript》(上)- 作用域和闭包
前端·javascript
小小小小宇8 小时前
前端PerformanceObserver使用
前端
zhangxingchao9 小时前
Flutter中的页面跳转
前端
前端风云志9 小时前
TypeScript实用类型之Omit
javascript
烛阴9 小时前
Puppeteer入门指南:掌控浏览器,开启自动化新时代
前端·javascript
全宝10 小时前
🖲️一行代码实现鼠标换肤
前端·css·html
小小小小宇11 小时前
前端模拟一个setTimeout
前端