欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue實(shí)現(xiàn)ajax滾動(dòng)下拉加載,同時(shí)具有l(wèi)oading效果(推薦)

 更新時(shí)間:2017年01月11日 09:04:50   作者:還能再菜點(diǎn)嗎  
這篇文章主要介紹了vue實(shí)現(xiàn)ajax滾動(dòng)下拉加載,同時(shí)具有l(wèi)oading效果的實(shí)現(xiàn)代碼,文章包括難點(diǎn)說明,介紹的非常詳細(xì),感興趣的朋友參考下

代碼如下所示:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>vue測試ajax的使用</title>
<meta id="viewport" name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<style>
*{ padding:0; margin:0}
.list ul li{padding:10px 5px 10px 10px;overflow:hidden;zoom:1;position:relative;border-bottom:1px solid #e8e8e8;}
.list ul li .img{margin-right:10px;display:block;width:60px;float:left;}
.list ul li img{width:60px;height:60px;border-radius:8px;}
.list ul li p{-webkit-box-flex:1;color:#777;overflow:hidden;padding-right:70px;}.list ul li p em{margin:7px 0;}
.list ul li p a{display:block;height:16px;line-height:16px;overflow:hidden;font-size:15px;}
.list ul li p span{display:block;line-height:16px;height:16px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;font:12px "\5FAE\8F6F\96C5\9ED1";}
.list ul li p u{margin:0 6px;padding:0 6px;border-left:1px solid #d9d9d9;border-right:1px solid #d9d9d9;}
.list ul li .btn {width: 40px;height: 25px;padding-top: 35px;color: #65bb0a;line-height:25px;text-align:center;background: none;position:absolute;right:5px; top:12px}
.list ul li .btn .bg {position: absolute;left: 0;top: 0;display: inline-block;width: 100%;height: 30px;repeat;background-size: 26px auto;}
.get-more,.loading{display:block;padding:15px 0; line-height:16px;text-align:center;font-size:14px;}
.loading{width:75px; margin:0 auto; background:url(imgs/loading.gif) 0 center no-repeat; padding-left:15px; background-size:13px auto}
</style>
</head>
<body>
<div class="list" id="app" v-scroll="getMore">
 <ul>
 <li v-for="item in games">
  <a v-bind:href="item.url" class="img"><img v-bind:src="item.img"></a>
  <p>
  <a v-bind:href="item.url">{{item.title}}</a>
  <em class="lstar4"></em>
  <span>{{item.server}}<u>39.9M</u>v2.1.3</span>
  </p>
  <a v-bind:href="item.url" class="btn"><em class="bg"></em>下載</a>
 </li>
 </ul>
 <div>
 <p class="get-more" v-on:click="getMore()" v-show="switchShow">點(diǎn)擊加載更多</p>
 <p class="loading" v-show="!switchShow">加載中...</p>
 </div>
</div>
<script src="js/vue.js"></script>
<script src="http://cdn.bootcss.com/vue-resource/1.0.3/vue-resource.min.js"></script>
<!--<script src="http://211.149.193.19:8090/vue-tutorials/04.OAuth/jquery-zepto/js/zepto.js"></script>-->
<script>
var vm = new Vue({
 el:'#app',
 data: {
 url: 'http://*******.com/dynamic.php?s=/Afs/ajaxHisTestServerData/cate_id/4/sta/',
 nowPage: 0,
 switchShow:false,
 games: []
 },
 methods: {
 moreFn: function (itemIndex) {
  // console.log(this.nowPage)
  this.$http.jsonp(this.url + itemIndex*10).then(function (response) {
  this.games=this.games.concat(response.body);
  this.switchShow=!this.switchShow;
  }, function (response) {
   console.log(response)
  });
 },
 getMore: function () {
  this.switchShow=!this.switchShow;
  this.nowPage++;
  this.moreFn(this.nowPage);
 },
 init: function () {
  this.moreFn(this.nowPage);
 }
 },
 directives: {// 自定義指令
 scroll: {
 bind: function (el, binding){
  window.addEventListener('scroll', function () {
  if(document.body.scrollTop + window.innerHeight >= el.clientHeight) {
  var fnc = binding.value; 
  fnc(); 
  }
  })
 }
 }
 }
})
vm.init();
</script>
</body>
</html>

功能介紹:

1.vue進(jìn)行ajax請求加載;

2.實(shí)現(xiàn)滾動(dòng),點(diǎn)擊加載數(shù)據(jù);

3.通過自定義實(shí)現(xiàn)loading 效果;

難點(diǎn):

1.需要官方的vue-resource組件,進(jìn)行ajax請求,所以需要了解該API;

2.loading,通過v-show進(jìn)行判斷顯示不同的loading 效果;

3.自定義指令,也是最難點(diǎn),所以需要了解基本的自定義指令A(yù)PI;

以上所述是小編給大家介紹的vue實(shí)現(xiàn)ajax滾動(dòng)下拉加載,同時(shí)具有l(wèi)oading效果(推薦),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

  • 在Vue框架中配置Mock服務(wù)器的方法

    在Vue框架中配置Mock服務(wù)器的方法

    在前端開發(fā)中,如果需要模擬后端數(shù)據(jù),而又不想開發(fā)一個(gè)后端服務(wù)器, 則可以借助mock.js配置一個(gè)后端服務(wù)器來返回前端需要的數(shù)據(jù),本文將會分別介紹在Quasar項(xiàng)目和Vite項(xiàng)目中Mock服務(wù)器的配置方法
    2022-12-12
  • Vue項(xiàng)目中常用的實(shí)用技巧匯總

    Vue項(xiàng)目中常用的實(shí)用技巧匯總

    如果說是JQuery是手工作坊,那么Vue.js就像是一座工廠,雖然Vue.js做的任何事情JQuery都可以做,但無論是代碼量還是流程規(guī)范性都是前者較優(yōu),這篇文章主要給大家匯總介紹了關(guān)于Vue項(xiàng)目中常用的實(shí)用技巧,需要的朋友可以參考下
    2021-07-07
  • vue實(shí)現(xiàn)的組件兄弟間通信功能示例

    vue實(shí)現(xiàn)的組件兄弟間通信功能示例

    這篇文章主要介紹了vue實(shí)現(xiàn)的組件兄弟間通信功能,結(jié)合實(shí)例形式分析了vue兄弟組件間通信的原理與相關(guān)操作技巧,需要的朋友可以參考下
    2018-12-12
  • vue中json格式化顯示數(shù)據(jù)(vue-json-viewer)

    vue中json格式化顯示數(shù)據(jù)(vue-json-viewer)

    這篇文章主要給大家介紹了關(guān)于vue中json格式化顯示數(shù)據(jù)(vue-json-viewer)的相關(guān)資料,Vue-json-viewer是一個(gè)Vue組件,用于在Vue應(yīng)用中顯示JSON數(shù)據(jù)的可視化工具,需要的朋友可以參考下
    2024-05-05
  • vue全局方法plugins/utils的實(shí)現(xiàn)示例

    vue全局方法plugins/utils的實(shí)現(xiàn)示例

    很多時(shí)候我們會在全局調(diào)用一些方法,本文主要介紹了vue全局方法plugins/utils的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-07-07
  • 深入探究Vue中探究組合式API的奧秘

    深入探究Vue中探究組合式API的奧秘

    Vue?3中引入了組合式API,它是一種新的代碼組織方式,旨在讓開發(fā)者更靈活地組織和重用Vue組件的邏輯,下面我們就來學(xué)習(xí)一下Vue中常見組合式API的使用吧
    2023-11-11
  • Vue實(shí)現(xiàn)全局的toast組件方式

    Vue實(shí)現(xiàn)全局的toast組件方式

    這篇文章主要介紹了Vue實(shí)現(xiàn)全局的toast組件方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • vue中el-date-picker type=daterange日期清空時(shí)不回顯的解決

    vue中el-date-picker type=daterange日期清空時(shí)不回顯的解決

    這篇文章主要介紹了vue中el-date-picker type=daterange日期清空時(shí)不回顯的解決方案,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-07-07
  • nuxt+axios解決前后端分離SSR的示例代碼

    nuxt+axios解決前后端分離SSR的示例代碼

    這篇文章主要介紹了nuxt+axios解決前后端分離SSR的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-10-10
  • vue3點(diǎn)擊不同的菜單頁切換局部頁面實(shí)現(xiàn)方法

    vue3點(diǎn)擊不同的菜單頁切換局部頁面實(shí)現(xiàn)方法

    這篇文章主要給大家介紹了關(guān)于vue3點(diǎn)擊不同的菜單頁切換局部頁面實(shí)現(xiàn)的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用vue3具有一定的參考價(jià)值,需要的朋友可以參考下
    2023-08-08

最新評論