Vue form 表单提交+ajax异步请求+分页效果


Posted in Javascript onApril 22, 2017

废话不多说了,直接给大家贴代码了,具体代码如下所示:

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width,initial-scale=1">
 <meta charset="UTF-8"/>
 <title>异步参数上传</title>
 <link rel="stylesheet" type="text/css" href="${ctx }/css/bootstrap.min.css" rel="external nofollow" >
 <#--<link href="css/fileinput.css" rel="external nofollow" media="all" rel="stylesheet" type="text/css"/>-->
 <link href="${ctx }/css/fileinput.css" rel="external nofollow" media="all" rel="stylesheet" type="text/css"/>
 <link rel="stylesheet" type="text/css" href="${ctx }/css/css.css" rel="external nofollow" />
 <#--<link rel="stylesheet" type="text/css" href="${ctx }/css/style.css" rel="external nofollow" />-->
 <link rel="stylesheet" type="text/css" href="${ctx }/css/subwelcome.css" rel="external nofollow" />
 <script>var $context = {};
 $context.ctx = '${ctx}';
 $context.resources = '${ctx}/resources';
 </script>
</head>
<body>
<div id="app" class="htmleaf-container">
 <div class="container kv-main">
  <br>
  <div style="margin-left: 200px;" class="robot-b-name">
   <a class=".btn btn-primary" href="">返回上传页面</a>
  </div>
  <br>
  <form @submit.prevent="submit" class="well form-inline">
   <input type="text" class="input-big" style="width: 500px" v-model.trim="batchInforRequestVO.appkey"
     placeholder="请输入appkey">
   <input type="text" class="input-group" style="width: 500px" v-model.trim="batchInforRequestVO.batchnum"
     placeholder="请输入批次号">
   <input type="hidden" class="input-group" style="width: 500px"
     v-model.trim="batchInforRequestVO.currentPage">
   <button type="submit" class="btn btn-info">查询</button>
  </form>
  <br>
  <!--提示框公共部分begining-->
  <div class="modal-mask" v-show="show">
   <div class="modal-confirm">
    <h4 class="confirm-header">
     <i class="iconfont icon-questioncircle"></i> {{ title }}
    </h4>
    <div class="confirm-content">
     {{ content }}
    </div>
    <div class="confirm-btns">
    <#--<button class="btn" v-on:click="opt(1)">取 消</button>-->
     <button class="btn btn-primary" v-on:click="opt(2)">确 定</button>
    </div>
   </div>
  </div>
  <br>
  <!--提示框公共部分ending-->
  <div class="modal-mask" v-show="showcontent">
   <div class="modal-confirm">
    <h4 class="confirm-header">
     <i class="iconfont icon-questioncircle"></i> {{ title }}
    </h4>
    <div class="confirm-content">
     {{ content }}
    </div>
    <div class="confirm-btns">
    <#--<button class="btn" v-on:click="opt(1)">取 消</button>-->
     <button class="btn btn-primary" v-on:click="opt(3)">确 定</button>
    </div>
   </div>
  </div>
  <div>查询结果</div>
  <!-- TableBegining -->
  <div>
   <table class="table table-striped table-bordered table-condensed">
    <tr>
     <th>批次号</th>
     <th>处理进度</th>
     <th>文件名称</th>
     <th>上传时间</th>
     <th>请求方法</th>
     <th>操作</th>
    </tr>
    <tr v-for="(batchInforResponseVO, index) in BatchInforResponseVO ">
     <td>{{batchInforResponseVO.batchNum}}</td>
     <td>{{batchInforResponseVO.processPercentage}}</td>
     <td>{{batchInforResponseVO.channelName}}</td>
     <td>{{batchInforResponseVO.inserTime}}</td>
     <td>{{batchInforResponseVO.requestAddre}}</td>
     <td><a id="opreat" v-on:click="defaultExport(index)" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >导出 </a><a
       v-on:click="redirectTo(index)" id="opreat" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >自定义导出 </a></td>
    </tr>
   </table>
  </div>
  <!-- TableEnding -->
  <!-- 分页部分Begining -->
  <div class="span6" style="width:25%;margin-right: 10px;float: right;">
   <div style="width: 500px;" id="DataTables_Table_0_length">
    <span> 每页10条记录 当前页{{batchInforRequestVO.currentPage}}</span>  
    <span>共{{totalPage}}页 <a id="previousPage" v-on:click="changePage(1)" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >←上一页</a>   <a
      id="nextPage" v-on:click="changePage(2)" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >下一页 →</a></span>
   </div>
  </div>
  <!-- 分页部分Ending -->
 </div>
</div>
</div>
</body>
<script type="text/javascript">
 window.history.go(1);
</script>
<script src="${ctx }/js/jquery/jquery-2.0.3.min.js"></script>
<script src="${ctx }/js/jquery.form.js"></script>
<script src="${ctx }/js/vue/vue.js"></script>
<script src="${ctx }/js/business/exportconfig.js" type="text/javascript"></script>
</html>
var vue = new Vue({
 el: '#app',
 data: {
  batchInforRequestVO: {
   currentPage: 1,
   appkey: '',
   batchnum: ''
  },
  show: false,
  showcontent: false,
  onCancel: false,
  onOk: false,
  totalPage: 0,
  title: '提示框',
  content: '加载......',
  message: '批量数据处理',
  BatchInforResponseVO: []
 },
 methods: {
  refreshTest: function () {
   location.reload(true)
  },
  //输入框增加方法
  add: function () {
   this.user.names.push({
    text: ""
   })
  },
  //输入框删除方法
  decrease: function (index) {
   if (!index == 0) {
    this.user.names.splice(index, 1)
   }
  },
  changePage: function (type) {
   if (type == '1') {
    debugger
    if (this.batchInforRequestVO.currentPage == '1') {
     vue.showcontent = true;
     vue.content = '已经是首页啦!';
     return
    }
    this.batchInforRequestVO.currentPage--;
    this.submit();
   }
   else if (type == '2') {
    this.batchInforRequestVO.currentPage++;
    debugger
    if (this.batchInforRequestVO.currentPage > this.totalPage) {
     this.batchInforRequestVO.currentPage--;
     vue.showcontent = true;
     vue.content = '已经是尾页啦!';
     return
    }
    this.submit();
   }
  },
  checkparam: function () {
   if (this.batchInforRequestVO.appkey == '' && this.batchInforRequestVO.batchnum == '') {
    vue.showcontent = true;
    vue.content = '查询参数不可以为空!';
    return false
   }
   else {
    return true
   }
  },
  opt(type){
   this.show = false
   if (type == '1') {
    if (this.onCancel) this.onCancel()
   }
   else if (type == '3') {
    this.showcontent = false
    if (this.onOk) this.onOk()
   }
   else {
    if (this.onOk) this.onOk()
    vue.refreshTest();
   }
   this.onCancel = false
   this.onOk = false
   document.body.style.overflow = ''
  },
  submit: function () {
   debugger
   var data = JSON.stringify(this.batchInforRequestVO); // 这里才是你的表单数据
   if (!vue.checkparam()) {
    return
   }
   ;
   //da.append("name", this.name)可以逐次添加多个参数
   $.ajax({
    url: '../interface/queryBatchInfor',
    data: data,
    type: 'POST',
    contentType: 'application/json',
    dataType: 'JSON',
    // cache: false,
    processData: false,// 告诉jQuery不要去处理发送的数据
    // contentType: false,// 告诉jQuery不要去设置Content-Type请求头
    success: function (data) {
     debugger
     if (data.respCode == 'success') {
      vue.BatchInforResponseVO = data.batchInforResponseVOList;
      vue.totalPage = data.totalPage;
     } else {
      vue.show = true;
      vue.content = data.respMsg;
     }
     console.log(data)
    },
    error: function (data) {
     vue.show = true;
     vue.content = '系统内部错误';
    }
   })
  },
  defaultExport: function ($index) {
   debugger
   var index = $index;
   window.location.href = $context.ctx + "../interface/defaultexcport?batchNum=" + this.BatchInforResponseVO[index].batchNum;
  },
  redirectTo: function ($index) {
   vue.showcontent = true;
   vue.content = '进行中......';
   debugger
   var index = $index;
   // window.location.href = $context.ctx + "../interface/to_autoconfig?batchNum="+ this.BatchInforResponseVO[index].batchNum;
  }
 }
})

以上所述是小编给大家介绍的Vue form 表单提交+ajax异步请求+分页效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对三水点靠木网站的支持!

Javascript 相关文章推荐
jquery绑定原理 简单解析与实现代码分享
Sep 06 Javascript
调用DOM对象的focus使文本框获得焦点
Feb 19 Javascript
jquery动态加载js/css文件方法(自写小函数)
Oct 11 Javascript
深入理解JavaScript系列(41):设计模式之模板方法详解
Mar 04 Javascript
浅析javascript的return语句
Dec 15 Javascript
详解jquery validate实现表单验证 (正则表达式)
Jan 18 Javascript
ES6新特性之字符串的扩展实例分析
Apr 01 Javascript
bootstrap栅格系统示例代码分享
May 22 Javascript
vue使用Axios做ajax请求详解
Jun 07 Javascript
angularJs复选框checkbox选中进行ng-show显示隐藏的方法
Oct 08 Javascript
Vue表情输入组件 微信face表情组件
Feb 11 Javascript
详解小程序横屏方案对比
Jun 28 Javascript
详解Vue 事件驱动和依赖追踪
Apr 22 #Javascript
JS使用cookie实现只出现一次的广告代码效果
Apr 22 #Javascript
利用JS实现简单的瀑布流加载图片效果
Apr 22 #Javascript
jQuery实现百度登录框的动态切换效果
Apr 21 #jQuery
HTML5+Canvas调用手机拍照功能实现图片上传(下)
Apr 21 #Javascript
微信JS-SDK选取手机照片上传功能
Apr 21 #Javascript
HTML5+Canvas调用手机拍照功能实现图片上传(上)
Apr 21 #Javascript
You might like
在PHP3中实现SESSION的功能(二)
2006/10/09 PHP
使用CodeIgniter的类库做图片上传
2014/06/12 PHP
跟我学Laravel之视图 &amp; Response
2014/10/15 PHP
使用PHP实现生成HTML静态页面
2015/11/18 PHP
PDO::commit讲解
2019/01/27 PHP
laravel 修改.htaccess文件 重定向public的解决方法
2019/10/12 PHP
PHP实现倒计时功能
2020/11/16 PHP
jQuery 使用手册(四)
2009/09/23 Javascript
JS中自定义定时器让它在某一时刻执行
2014/09/02 Javascript
node.js中的fs.mkdirSync方法使用说明
2014/12/17 Javascript
JS实现向表格行添加新单元格的方法
2015/03/30 Javascript
JavaScript实现横向滑出的多级菜单效果
2015/10/09 Javascript
基于JavaScript如何实现ajax调用后台定义的方法
2015/12/29 Javascript
jQuery插件FusionCharts绘制的2D双柱状图效果示例【附demo源码】
2017/05/13 jQuery
React应用中使用Bootstrap的方法
2017/08/15 Javascript
vue 实现小程序或商品秒杀倒计时
2019/04/14 Javascript
Vue+Django项目部署详解
2019/05/30 Javascript
layui 实现二级弹窗弹出之后 关闭一级弹窗的方法
2019/09/18 Javascript
JS面向对象编程基础篇(三) 继承操作实例详解
2020/03/03 Javascript
[01:56]无止竞 再出发——中国军团出征2017年DOTA2国际邀请赛
2017/07/05 DOTA
Python设计模式中单例模式的实现及在Tornado中的应用
2016/03/02 Python
django创建最简单HTML页面跳转方法
2019/08/16 Python
python编写计算器功能
2019/10/25 Python
pygame库实现俄罗斯方块小游戏
2019/10/29 Python
Python实现搜索算法的实例代码
2020/01/02 Python
AmazeUI 折叠面板的实现代码
2020/08/17 HTML / CSS
Clarks英国官方网站:全球领军鞋履品牌
2016/11/26 全球购物
家庭睡衣和家庭用品:Little Blue House
2018/03/18 全球购物
PatPat香港:婴童服饰和亲子全家装在线购物
2020/09/27 全球购物
JSP和EJB可以共享HttpSession么?EJB里面可以改变session里面的内容
2013/06/05 面试题
《学会待客》教学反思
2014/02/22 职场文书
竞争上岗演讲稿范文
2014/05/12 职场文书
2014派出所所长群众路线对照检查材料思想汇报
2014/09/18 职场文书
加强作风建设工作总结
2014/10/23 职场文书
卡特教练观后感
2015/06/08 职场文书
springboot中一些比较常用的注解总结
2021/06/11 Java/Android