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

}

});

相关推荐
折果17 分钟前
如何在vue项目中封装自己的全局message组件?一步教会你!
前端·面试
不死鸟.亚历山大.狼崽子21 分钟前
Syntax Error: Error: PostCSS received undefined instead of CSS string
前端·css·postcss
汪子熙21 分钟前
Vite 极速时代的构建范式
前端·javascript
叶常落21 分钟前
[react] js容易混淆的两种导出方式2025-08-22
javascript
跟橙姐学代码21 分钟前
一文读懂 Python 的 JSON 模块:从零到高手的进阶之路
前端·python
前端小巷子1 小时前
Vue3的渲染秘密:从同步批处理到异步微任务
前端·vue.js·面试
nightunderblackcat1 小时前
新手向:用FastAPI快速构建高性能Web服务
前端·fastapi
每天学习一丢丢2 小时前
SpringBoot + Vue实现批量导入导出功能的标准方案
vue.js·spring boot·后端
小码编匠2 小时前
物联网数据大屏开发效率翻倍:Vue + DataV + ECharts 的标准化模板库
前端·vue.js·echarts
欧阳天风2 小时前
分段渲染加载页面
前端·fcp