• Uni-App 实现资讯滚动


    项目需要实现资讯的滚动,使用了Swiper组件,实现了首页头部的资讯滚动,简单地做下笔记

    效果

    实现说明

    主要是使用了Swiper可以自动滚动的特性来实现,左边是一个图片,右边则是Swpier,且姜Swpier的滚动方向设置为垂直,然后就是样式的调整

    对了,我是从接口中请求到的一个列表数据,各位看代码的时候记得调整一下

    代码

    <template>
    	<view>
    		<view class="u-flex content">
    			<u-image @click="gotoList" class="icon" width="80" height="80"
    				src="https://img2020.cnblogs.com/blog/1210268/202110/1210268-20211018193858671-1201041615.png">
    			</u-image>
    
    			<swiper class="flex-1" :autoplay="true" :interval="2000" :circular="true"
    				style="height: 90rpx;padding: 10rpx;" :duration="1000" :vertical="true">
    				<swiper-item v-for="(item,i) in noticeList" :key="i">
    					<view @click="toNoticeDetail(item.noticeId)">
    						<view class="u-line-1 u-m-b-10 fontBlack">
    							{{item.noticeTitle}}
    						</view>
    						<view class="fontGrey u-line-1" style=" 100%;">
    							发布时间:{{item.issuedTime}} 来源:{{item.issuedBy}}
    						</view>
    					</view>
    				</swiper-item>
    			</swiper>
    		</view>
    	</view>
    </template>
    
    <script>
    	export default {
    		data() {
    			return {
    				noticeList: [],
    				pageSize: 3,
    				pageNum: 1,
    				total: null
    			}
    		},
    		mounted() {
    			this.getNoticeList()
    		},
    		methods: {
    			gotoList() {
    				uni.navigateTo({
    					url: "/pagesA/notice_list/notice_list"
    				})
    			},
    			getNoticeList() {
    				let url = "/dev-api/WechatTzggApi/list"
    				let param = {
    					pageSize: this.pageSize,
    					pageNum: this.pageNum,
    					issuedType: 1,
    					status: 0
    				}
    				let that = this
    				this.$http.get(url, param).then(res => {
    					uni.hideLoading()
    					if (res.code == 200) {
    						let rows = res.rows
    						rows.forEach(item => {
    							if (item.issuedTime != null) {
    								let index = item.issuedTime.indexOf(" ")
    								if (index != -1) {
    									item.issuedTime = item.issuedTime.substring(0, index)
    								}
    							}
    						})
    						that.noticeList.push(...rows)
    					}
    					console.log("通知公告列表数据...", res);
    				}).catch(err => {
    					uni.hideLoading()
    					console.log(err);
    				})
    			},
    			toNoticeDetail(id) {
    				uni.navigateTo({
    					url: "/pagesA/notice_detail/notice_detail?id=" + id
    				})
    			}
    		}
    	}
    </script>
    
    <style lang="scss" scoped>
    	.content {
    		padding: 20rpx;
    		// box-shadow: 0px 3rpx 15rpx rgba(0, 0, 0, 0.15);
    		background-color: $white;
    		margin: 20rpx;
    		border-radius: 10rpx;
    		display: flex;
    	}
    
    	.icon {
    		padding: 10rpx;
    	}
    
    	.fontGrey {
    		color: gray;
    		font-size: 28rpx;
    	}
    
    	.fontBlack {
    		font-size: 30rpx;
    		color: $black;
    	}
    </style>
    

    提问之前,请先看提问须知 点击右侧图标发起提问 联系我 或者加入QQ群一起学习 Stars-One安卓学习交流群 TornadoFx学习交流群:1071184701
  • 相关阅读:
    .net导出Excel几种方式比较
    各种loading加载中gif图标
    鼠标右键Table的td弹出多级菜单,双击td编辑
    解决远程连接超过最大数
    JQuery1.72中二个Bug,formhtml()方法与clone()方法的二个Bug进行重写
    Wijmo 2017路线图
    Wijmo 2016 V3发布
    ComponentOne 2016 V3 发布
    Angular2正式版发布,Wijmo抢先支持
    最好的Angular2表格控件
  • 原文地址:https://www.cnblogs.com/stars-one/p/15428047.html
Copyright © 2020-2023  润新知