Vue form 表單提交+ajax非同步請求+分頁效果,vueajax

來源:互聯網
上載者:User

Vue form 表單提交+ajax非同步請求+分頁效果,vueajax

廢話不多說了,直接給大家貼代碼了,具體代碼如下所示:

<!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非同步請求+分頁效果,希望對大家有所協助,如果大家有任何疑問請給我留言,小編會及時回複大家的。在此也非常感謝大家對幫客之家網站的支援!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.