码迷,mamicode.com
首页 > 移动开发 > 详细

vue.js - axios Get方法传参给 .net core webapi。

时间:2019-02-15 18:03:46      阅读:461      评论:0      收藏:0      [点我收藏+]

标签:fun   eth   通过   order   sel   info   pre   json   turn   

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 = 10;//页大小。
            int pageindex = 1;//第几页。
            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 - 1)).Take(pagesize).ToListAsync();
            return infors;
        }

 

vue.js - axios Get方法传参给 .net core webapi。

标签:fun   eth   通过   order   sel   info   pre   json   turn   

原文地址:https://www.cnblogs.com/longdb/p/10384518.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!