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("添加成功!");

}

});

相关推荐
Wect1 分钟前
LeetCode 39. 组合总和:DFS回溯解法详解
前端·算法·typescript
Wect4 分钟前
LeetCode 46. 全排列:深度解析+代码拆解
前端·算法·typescript
IT_陈寒5 分钟前
Vite 凭什么比 Webpack 快50%?揭秘闪电构建背后的黑科技
前端·人工智能·后端
颜酱6 分钟前
Dijkstra 算法:从 BFS 到带权最短路径
javascript·后端·算法
hi大雄35 分钟前
我的 2025 —— 名为《开始的勇气》🌱
前端·年终总结
从文处安1 小时前
「前端何去何从」一直写 Vue ,为何要在 AI 时代去学 React?
前端·react.js
aircrushin1 小时前
OpenClaw“养龙虾”现象的社会技术学分析
前端·后端
明君879971 小时前
#Flutter 的官方Skills技能库
前端·flutter
yuki_uix1 小时前
重新认识 React Hooks:从会用到理解设计
前端·react.js
林太白1 小时前
ref和reactive对比终于学会了
前端