您好,登錄后才能下訂單哦!
這篇文章主要介紹ajax請(qǐng)求+vue.js渲染+頁面加載的示例分析,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
1.導(dǎo)入js
<script type="text/javascript" src="<c:url value="/resources/lib/jquery/jquery-1.11.0.min.js" />"></script> <!--標(biāo)準(zhǔn)mui.css--> <link href="<c:url value=" rel="external nofollow" rel="external nofollow" /resources/mui/css/mui.min.css" />" rel="stylesheet"> <!--App自定義的css--> <link href="<c:url value=" rel="external nofollow" rel="external nofollow" /resources/mui/css/app.css" />" rel="stylesheet"> <script src="<c:url value="/resources/vue/vue.js"/>"></script>
2.body主體
<body> <div class="main"> <header class="mui-bar mui-bar-nav"> <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a> <h2 class="mui-title">訂單管理</h2> </header> <div class="mui-content"> <div class="mui-content-padded" > <h6>請(qǐng)輸入地址:</h6> <div class="mui-input-row mui-search"> <input type="search" id="searchInput" class="mui-input-clear" placeholder=""> </div> </div> <%--<div > <input type="text" class="mui-input-clear" id="searchInput" placeholder="請(qǐng)輸入地址" > <button type="submit" class="mui-btn mui-btn-primary" onclick="submitSearch()"> 搜索 </button> </div>--%> <div ></div> <ul class="mui-table-view mui-table-view-striped mui-table-view-condensed" id="msgUl"> <li class="mui-table-view-cell" id="list" v-for="li in list" :key="li.orderBaseId"> <div class="mui-slider-right mui-disabled" @click="orderDetail(li.orderBaseId)"> <a class="mui-btn mui-btn-grey"<%-- v-bind:href="li" rel="external nofollow" --%>/>詳情</a> </div> <div class="mui-table mui-slider-handle" @click="skipDetail(li.orderBaseId)"> <div class="mui-table-cell mui-col-xs-10"> <div class="mui-table-cell"> <h5 >姓名:{{li.customerName}}</h5> </div> <p class="">地址:{{li.customerAddress}}</p> </div> </div> </li> </ul> </div> </div> </body>
3.js代碼塊
<script src="<c:url value="/resources/mui/js/mui.min.js"/>"></script> <script> var vm = new Vue({ el: '.main', data: function () { return { list: [] } }, methods: { skipDetail: function (id) { window.location.href = '/mobile/admin/orderBase/getOrderBaseEditPage.action?orderBaseId='+id; }, orderDetail:function (id) { window.location.href='/mobile/admin/orderDetails/getOrderDetailsListPage.action?orderBaseId='+id; } } }); var indexs=1; leavePage(); function leavePage(srh) { if(srh==1){ indexs=1; $("#msgUl").html(""); } $.ajax({ url:'<c:url value="/mobile/admin/orderBase/getOrderBaseListJSON.action" />', async:false, data:{ customerAddress:$(".mui-input-clear").val(), page:indexs, rows:9 }, dataType:'json',//服務(wù)器返回json格式數(shù)據(jù) contentType: "application/x-www-form-urlencoded; charset=utf-8", type:'post',//HTTP請(qǐng)求類型 success:function(data){ if(data.rows.length>0){ indexs+=1; } console.log(data); vm.list.push.apply(vm.list,data.rows); console.log(vm.list) } }); } $(document).ready(function(){ var range = 50; //距下邊界長(zhǎng)度/單位px var elemt = 500; //插入元素高度/單位px var maxnum = 20; //設(shè)置加載最多次數(shù) var num = 1; var totalheight = 0; var main = $(".mui-content"); //主體元素 $(window).scroll(function(){ var srollPos = $(window).scrollTop(); //滾動(dòng)條距頂部距離(頁面超出窗口的高度) /* console.log("滾動(dòng)條到頂部的垂直高度: "+$(document).scrollTop()); console.log("頁面的文檔高度 :"+$(document).height()); console.log('瀏覽器的高度:'+$(window).height());*/ totalheight = parseFloat($(window).height()) + parseFloat(srollPos); if(($(document).height()-range) <= totalheight && num != maxnum) { console.log(indexs); /* indexs+=1;*/ leavePage(); } }); }); //地址模糊搜索 $("#searchInput").change(function () { /*alert($(".mui-input-clear").val());*/ leavePage(1); }) /* function submitSearch() { leavePage(1); }*/ mui.init({ swipeBack:true //啟用右滑關(guān)閉功能 }); </script>
以上是“ajax請(qǐng)求+vue.js渲染+頁面加載的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。