Vue form 表单提交+ajax异步请求+分页效果
程序员文章站
2022-09-03 10:10:33
废话不多说了,直接给大家贴代码了,具体代码如下所示:
废话不多说了,直接给大家贴代码了,具体代码如下所示:
<!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异步请求+分页效果,希望对大家有所帮助