• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com专业计算机教程网站
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • html/xhtml
  • html5
  • CSS
  • XML/XSLT
  • Dreamweaver教程
  • Frontpage教程
  • 心得技巧
  • bootstrap
  • vue
  • AngularJS
  • HBuilder教程
  • css3
  • 浏览器兼容
  • div/css
  • 网页编辑器
  • axure
您的位置:首页 > 网页设计 >vue > vue实现ajax滚动下拉加载,同时具有loading效果(推荐)

vue实现ajax滚动下拉加载,同时具有loading效果(推荐)

作者:还能再菜点吗 字体:[增加 减小] 来源:互联网 时间:2017-05-30

本文主要包含vue.js ajax,vue2.0 ajax,vue ajax,vue中ajax,vue.js ajax请求等相关知识,还能再菜点吗 希望在学习及工作中可以帮助到您

代码如下所示:

<!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">点击加载更多</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>
</div>

功能介绍:

1.vue进行ajax请求加载;

2.实现滚动,点击加载数据;

3.通过自定义实现loading 效果;

难点:

1.需要官方的vue-resource组件,进行ajax请求,所以需要了解该API;

2.loading,通过v-show进行判断显示不同的loading 效果;

3.自定义指令,也是最难点,所以需要了解基本的自定义指令API;

以上所述是小编给大家介绍的vue实现ajax滚动下拉加载,同时具有loading效果(推荐),希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

</div>

您可能想查找下面的文章:

  • 使用vue框架 Ajax获取数据列表并用BootStrap显示出来
  • Vue form 表单提交+ajax异步请求+分页效果
  • Vue.js展示AJAX数据简单示例讲解
  • vue实现ajax滚动下拉加载,同时具有loading效果(推荐)
  • Javascript vue.js表格分页,ajax异步加载数据
  • Vue.js Ajax动态参数与列表显示实现方法
  • vue.js 表格分页ajax 异步加载数据

相关文章

  • 2017-05-30使用vue框架 Ajax获取数据列表并用BootStrap显示出来
  • 2017-05-30vue日期组件 支持vue1.0和2.0
  • 2017-05-30探究Vue.js 2.0新增的虚拟DOM
  • 2017-05-30Vue.js 递归组件实现树形菜单(实例分享)
  • 2017-05-30关于Vue.js 2.0的Vuex 2.0 你需要更新的知识库
  • 2017-05-30Vue.2.0.5过渡效果使用技巧
  • 2017-05-30Vue.js -- 过滤器使用总结
  • 2017-05-30windows下vue-cli导入bootstrap样式
  • 2017-08-19Vue 实现登录拦截(二)
  • 2017-05-30详解Vue 动态添加模板的几种方法

文章分类

  • html/xhtml
  • html5
  • CSS
  • XML/XSLT
  • Dreamweaver教程
  • Frontpage教程
  • 心得技巧
  • bootstrap
  • vue
  • AngularJS
  • HBuilder教程
  • css3
  • 浏览器兼容
  • div/css
  • 网页编辑器
  • axure

最近更新的内容

    • 源码分析Vue.js的监听实现教程
    • Vue.js 表单校验插件
    • vue2.0结合DataTable插件实现表格动态刷新的方法详解
    • vue基于Vue2.0和高德地图的地图组件实例
    • 详解Vue中使用v-for语句抛出错误的解决方案
    • vue的Virtual Dom实现snabbdom解密
    • 前端框架Vue.js构建大型应用浅析
    • Vue开发过程中遇到的疑惑知识点总结
    • vuejs响应用户事件(如点击事件)
    • 详解Vue用axios发送post请求自动set cookie

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有