VUE学习(十七) VUE3使用axios post的时候参数传递为空值
1.在使用axios发现post到后端的参数值变为空值。多次测试后发现只有使用下面的方法可用。参数名必须为字符串。参数要写成paramss 类型才行。2.后台的WEBAPI。
·
1.在使用axios发现post到后端的参数值变为空值。单独测试WEBAPI是OK的,这就证明在axios传值的时候出现问题了。
找了几种方法测试后发现只有使用下面的方法可用。参数名必须为字符串。参数要写成paramss 类型才行
//定义参数
let paramss = reactive({
"patientName": "patientName",
"barcode": "barcode",
})
const TestAxiosPost = () => {
// axios.post(webapiAddr + `Patient/HttpPostTest`, {
// //axios.post(`Patient/PrintLabe`, {
// //params:
// data: {
// "patientName": "patientName",
// "Barcode": "Barcode",
// }
// })
// .then(function (response) {
// //demo1.tableData = response.data
// //demo1.list = demo1.tableData
// console.log('print ok');
// console.log(response);
// //console.log(demo1.tableData);
// })
// .catch(function (error) {
// console.log(error);
// });
//给参数赋值
paramss.patientName="张三"
paramss.barcode ="1234"
axios.post(webapiAddr + `Patient/HttpPostTest`, paramss)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
}
2.后台的WEBAPI
更多推荐
已为社区贡献9条内容
所有评论(0)