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

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;
        }