Vue+Vux学习案例(五)—构建开源中国微信版(轮播图实现)
来源:互联网 发布:雷劈数算法 编辑:程序博客网 时间:2024/06/05 02:14
上篇:Vue+Vux学习案例(四)—构建开源中国微信版(增加资讯详情,集成Vuex)
使用Scroller组件完成了滑动列表展示信息,这篇介绍下轮播图集成实现:
首先import我们需要的Swiper组件,
import Swiper from 'vux/dist/components/swiper'
后面还要在components 中注册上,否则页面上是无法显示出来的,
页面代码:
<swiper :list="imgs" auto style="width:100%;margin:0 auto;" height="180px" dots-class="custom-bottom" dots-position="center"></swiper>
调整宽度width为100%铺满,高度自动调节,这里我们的图片分辨率需要设计合理,
整个代码写在NewsList.vue里面了,下面看完整代码:
<template> <div> <swiper :list="imgs" auto style="width:100%;margin:0 auto;" height="180px" dots-class="custom-bottom" dots-position="center"></swiper> <scroller lock-x scrollbar-y height="360px" :prevent-default="false" v-ref:scroller> <div class="news-wrap"> <cell v-for="x in Objlist" :title="x.title" v-link="{path: '/newsdetail',query:{id:x.id,tag:'资讯'}}" :inline-desc='x.body'> <img class="ic_img" slot="icon" src="../assets/image/ic_label_today.png"> <div> <span class="pubdate">{{x.pub_date}}</span> </div> </cell> </div> </scroller> </div></template><style>.ic_img{position:absolute; top:10px; left: 5px;width:15px;height:15px;}.weui_cell_bd>p{ font-size:15px;}.vux-label-desc{ padding-right:15px;}.weui_cell_bd.weui_cell_primary{padding-left:5px;}.news-wrap { height: 1800px; overflow: hidden;}.pubdate{font-size:5px;}</style><script> import Swiper from 'vux/dist/components/swiper' import Scroller from 'vux/dist/components/scroller' import Cell from 'vux/dist/components/cell' import Group from 'vux/dist/components/group' import { getList } from '../utils/api' import Divider from 'vux/dist/components/divider' const imgList = [ 'http://file06.16sucai.com/2016/0222/17714c3b51079911760e5ef7fdb553f6.jpg', 'http://pic.58pic.com/58pic/15/67/98/93C58PICjeM_1024.jpg', 'http://file06.16sucai.com/2016/0315/1df566087c24a94cd9534bc9bc1871ff.jpg' ] const urlList = imgList.map((one, index) => ({ url: 'javascript:', //这里填写图片点击的链接 img: one })) export default{ data(){ return{ ishow:false, Objlist:[], pageIndex:1, catalog:0, imgs:urlList, } }, components:{ Scroller, Cell, Group, Divider, Swiper }, ready () { this.getList() }, methods:{ async getList() { let data =await getList(this.pageIndex, this.catalog) console.log(data) var news_list=data.result.items; if(news_list.length>0){ this.ishow=true for(var i=0;i<news_list.length;i++){ var time = news_list[i].pubDate; var bngDate = new Date(time.replace("-", "/").replace("-", "/")); var endDate = new Date(); var minutes = (endDate.getTime()-bngDate.getTime())/60/1000; if(minutes>=60){ minutes=minutes/60; var datetime=parseInt(minutes); if(datetime>=48){ news_list[i].pubDate="2天前" }else if(datetime>=24){ news_list[i].pubDate="昨天" }else{ news_list[i].pubDate=datetime+ "小时以前" } }else{ var minute=parseInt(minutes); news_list[i].pubDate=minute+ "分钟以前" } this.Objlist.push(news_list[i]); } } this.locked = false this.loading = false},load (uuid) { setTimeout(() => { this.getList(); this.$broadcast('pulldown:reset', uuid) }, 1000) }, } }</script>
效果如下:
源码下载点这里
项目运行:npm run dev ,这里代码的端口修改在config目录index.js文件中,
本项目代码运行起来后,可以打开http://localhost:8082浏览
0 0
- Vue+Vux学习案例(五)—构建开源中国微信版(轮播图实现)
- Vue+webpack+Vux学习案例(二)—构建开源中国微信版(开篇)
- Vue+Vux学习案例(三)—构建开源中国微信版(添加网络通信)
- Vue+Vux学习案例(四)—构建开源中国微信版(增加资讯详情,集成Vuex)
- Vue+webpack学习案例(一)-构建Vue项目
- Vue+Vux+router
- Vue+Vux项目实践
- vue搭配vux-ui框架
- 在vue中使用vux
- vue状态管理vue-vux使用
- 实现vux组件跳转
- Vue学习之环境构建--------vue-cli构建vue项目
- Vue学习笔记五
- Appcan+vue+vux+webpack开发app(原创)
- 在我眼中vue/vux的钩子
- laravel5.4+vue+element+vux环境搭建
- 一、Vue中使用Vux的配置
- Vue中使用vux配置详解
- c++ 打印机删除操作
- linker command failed with exit code 1
- VxWorks编写服务器模板
- binbinyang--3.MPAndroidChart开源图表库---饼状图
- php断点续传之文件分割合并
- Vue+Vux学习案例(五)—构建开源中国微信版(轮播图实现)
- TCP/IP,http,socket,长连接,短连接
- 9个基于Java的搜索引擎框架
- ZCMU—1138
- 12.10
- 对象转url
- 学习嵌入式开发技术高效方法总结
- 使用css设置图片背景透明,文字不透明
- Dotnet 资源