如下:
export default {
name: "longParam",
data() {
return {
model: {
id:'',
name:'',
content:''
}
};
},
methods: {
//model作为参数调用接口,后台用实体接收
addModel: function() {
var that = this;
axios
.post("xx/xxx/AddModel",{params:that.model})
.then(function(response) {
var data = response.data;
if (data.status == 0) {
}
})
.catch(function(error) {
console.log(error);
});
}
}
};
</script>
后台代码:
[HttpPost]
public ActionResult AddModel(Model model)
{
//逻辑代码
}
以上代码中:如果content允许的内容过长,就会添加不成功,就需要修改调用接口的方式,如下
export default {
name: "longParam",
data() {
return {
model: {
id:'',
name:'',
content:''
}
};
},
methods: {
//model作为参数调用接口,后台用实体接收,将model直接作为参数传递,删除params
addModel: function() {
var that = this;
axios
.post("xx/xxx/AddModel",that.model)
.then(function(response) {
var data = response.data;
if (data.status == 0) {
}
})
.catch(function(error) {
console.log(error);
});
}
}
};
</script>
后台接口在接收的时候,在调用参数前添加[FromBody],如下:
[HttpPost]
public ActionResult AddModel([FromBody]Model model)
{
//逻辑代码
}
|