vue.js - axios Get、Post方法传参给 .net core webapi。
一:axios中是 Get请求:
1:在vue项目中通过params属性携带数据:
let _self = this;
axios({
method:'get',
url:'http://localhost:5000/api/StuInFors/GetEFAsync/',
params:{pagesize:10,pageindex:2}
}).then(function(resp){
//document.write(JSON.stringify(resp.data));
console.log(resp.status);
_self.apidatas = resp.data; });
2:然后.net core webapi 中通过Query取出数据:
[HttpGet]
public async Task<List<InforEF>> GetEFAsync()//int pagesize,int pageindex)
{
int pagesize = ;//页大小。
int pageindex = ;//第几页。
if (Request.Query.ContainsKey("pagesize"))
{
pagesize = Convert.ToInt32(Request.Query["pagesize"]);
pageindex = Convert.ToInt32(Request.Query["pageindex"]);
} //Skip(5),忽略前面的 5 个
//int pagesize = 10;//页大小。
//int pageindex = 1;//第几页。
//所以Skip(pagesize * (pageindex - 1)),Take(pagesize);
List<InforEF> infors = await _context.Infortb.OrderBy(infor => infor.Fid).Skip(pagesize * (pageindex - )).Take(pagesize).ToListAsync();
return infors;
}
二:axios中是 Post 请求:
1:vue中通过params或者data属性携带数据:
rowupdateclick(row) //added by longdb 2019.2.16
{
let _self = this; this.$confirm('保存, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
center: true
}).then(() => { axios({
method:'post',
data:[{
'FSaleNo':row.FSaleNo,
'FSaleName':row.FSaleName ,
'FSaleQty':row.FSaleQty,
'FSaleAmount':row.FSaleAmount,
'FSaleType':row.FSaleType,
'FSaleStatus':row.FSaleStatus
}],
params:{FSaleNo:row.FSaleNo,FSaleAmount:row.FSaleAmount},
url:"http://localhost:5000/api/SalesOrder/PostForUpdate/",//'http://172.17.192.161/WebApiAndroid/api/StuInFors/Post/',
}).then(function(resp){
console.log(resp.status);
if(resp.status == )
{
_self.$message({
type: 'success',
message: '保存成功!'+resp.data
});
}
}); }).catch(() => {
this.$message({
type: 'info',
message: '已取消保存'
});
});
}
2:如果是通过params属性,则在.net core webapi中的取法同Get请求。如果是通过data属性,则如下取法:
public async Task<string> PostForUpdate()//[FromBody] string value)
{
string retvalue = "failed";
Stream stream = Request.Body; if (stream != null)
{
using (var reader = new StreamReader(stream, Encoding.UTF8))
{
string data = await reader.ReadToEndAsync(); DataTable dt = JSONInterFace.JsonToDatableWithJsonNet(data); if (dt != null && dt.Rows.Count > )
{
string sql = "update TSaleOrder set FSaleAmount='" + dt.Rows[]["FSaleAmount"].ToString() + "' where FSaleNo='" + dt.Rows[]["FSaleNo"].ToString() + "'";
if (DBHelper.DBExecute(sql))
{
retvalue = "success";
}
//retvalue = DBHelper.sqlBulkCopyData(dt, "TSaleOrder");
}
}
}
return retvalue;
}
vue.js - axios Get、Post方法传参给 .net core webapi。的更多相关文章
- vue 使用 axios 时 post 请求方法传参无法发送至后台
axios 时 post 请求方法传参无法发送至后台报错如下 Response to preflight request doesn't pass access control check: No ' ...
- vue router使用query和params传参的使用
传参是前端经常需要用的一个操作,很多场景都会需要用到上个页面的参数,本文将会详细介绍vue router 是如何进行传参的,以及一些小细节问题.有需要的朋友可以做一下参考,希望可以帮到大家. Vue ...
- (转)vue router 如何使用params query传参,以及有什么区别
写在前面: 传参是前端经常需要用的一个操作,很多场景都会需要用到上个页面的参数,本文将会详细介绍vue router 是如何进行传参的,以及一些小细节问题.有需要的朋友可以做一下参考,喜欢的可以点波赞 ...
- vue router 如何使用params query传参,以及有什么区别
写在前面: 传参是前端经常需要用的一个操作,很多场景都会需要用到上个页面的参数,本文将会详细介绍vue router 是如何进行传参的,以及一些小细节问题.有需要的朋友可以做一下参考,喜欢的可以点波赞 ...
- js中使用进行字符串传参
在js中拼接html标签传参时,如果方法参数是字符串需要加上引号,这里需要进行字符转义 <a href='javascript:addMenuUI("+"\"&qu ...
- MyBatis dao层 方法传参
MyBatis dao层 方法传参有三种方法. 1. 以下标的方法获取参数. <update id="insertSuccessKilled"> INSER ...
- EasyUI queryParams属性 在请求远程数据同时给action方法传参
http://www.cnblogs.com/iack/p/3530500.html?utm_source=tuicool EasyUI queryParams属性 在请求远程数据同时给action方 ...
- javascript 字符串方法传参
javascript 字符串方法传参由于嵌套的单引号,双引号过多.有点混乱.. 正确方法如下: ' <td align="left"><input type= ...
- 再谈Java方法传参那些事
把一个变量带进一个方法,该方法执行结束后,它的值有时会改变,有时不会改变.一开始会觉得--“好神奇呀”.当我们了解java内存分析的知识后,一切都是那么简单明了了--“哦,这么回事呀”.但是今天的上机 ...
随机推荐
- 关于Android控件EditText的属性InputType的一些经验,java组合多个参数
关于Android控件EditText的属性InputType的一些经验 2013-11-14 15:08:02| 分类: 默认分类|举报|字号 订阅 1.InputType属性在代码中 ...
- 20155319 2016-2017-2 《Java程序设计》第七周学习总结
20155319 2016-2017-2 <Java程序设计>第七周学习总结 教材学习内容总结 第十二章 Lambda 如果使用JDK8的话,可以使用Lambda特性去除重复的信息. 在只 ...
- 455. Assign Cookies
static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...
- 使用WindowsFormsApplicationBase实现引导界面
1.需要添加对Microsoft.VisualBasic 引用, 2.准备frmMain,frmSplash两个窗口 说明: frmSplash在主线程上建立,但是在独立线程上进行消息循 ...
- db_autopwn
nmap -Pn -sV -oX dmz 192.168.1.0/24 db_import /root/dmz db_hosts db_hosts -d ip db_services db_hosts ...
- windows server2012怎样关机怎样重启-详细教程
| 浏览:1991 | 更新:2014-12-15 17:33 1 2 3 4 5 6 分步阅读 百度经验:jingyan.baidu.com windows server2012和以往有些不同,关机 ...
- JVM GC 机制与性能优化
目录(?)[+] 1 背景介绍 与C/C++相比,JAVA并不要求我们去人为编写代码进行内存回收和垃圾清理.JAVA提供了垃圾回收器(garbage collector)来自动检测对象的作用域),可自 ...
- 使用VMWare12.0安装Ubuntu系统
使用VMWare12.0安装Ubuntu系统 Vmware12的虚拟机的文档说明: http://pubs.vmware.com/workstation-12/index.jsp#com.vmware ...
- 安装Greenplum-perfmon-web监控软件遇到的问题及解决
环境 Product Version Pivotal Greenplum (GPDB) 4.3.x Pivotal Greenplum Command Center (GPCC) Others ...
- 执行计划--Adhoc和Prepare
在和SQLPass讨论adhoc和Prepare时,有各自不同的观点,我来发表下我的理解,不对之处,敬请指出! Adhoc(即席查询):没有参数化的查询计划会被标记为adhoc,adhoc不能理解为该 ...