uniapp - 填充页面

news2024/10/5 21:16:54

在上一篇文章中,创建了一个空白的文章模块页面。在这一篇文章,让我们来向页面中填充内容。

目录

  • 页面效果
  • 涉及uniapp组件
    • 1.view
    • 2.swiper
    • 3.scroll-view
    • 4.属性解读
      • 1) class="style1 style2 .."
      • 2) circular单属性无赋值
      • 3) :autoplay="autoplay"
      • 4) @scrolltolower=“lower”属性前加@
  • 一、顶部banner图
  • 二、静态按钮列表
  • 三、横向滚动图
  • 四、动态列表 + 详情跳转
  • 五、详情页面
  • 参考资料

页面效果

填充前的页面
![填充前](https://img-blog.csdnimg.cn/direct/2a1b2998b39a4c89a3a70ce1a7b68526.png

填充后的页面
在这里插入图片描述

涉及uniapp组件

1.view

视图容器,类似传统html中的div,用于包裹各种元素的内容。

2.swiper

滑块视图,可上下和左右滑动,一般作为banner轮播图。
在这里插入图片描述

3.scroll-view

区域滚动视图,有纵向滚动和横向滚动。
在这里插入图片描述

4.属性解读

例子:
a.<swiper class="article-swiper" circular :autoplay="autoplay" :indicator-dots="true" :duration="1000"></swiper>

b.<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" show-scrollbar="true" @scrolltoupper="upper"
				@scrolltolower="lower" @scroll="scroll" ></scroll-view>

1) class=“style1 style2 …”

class赋值的是自定义样式,具体样式定义内容在vue文件的

2) circular单属性无赋值

等价于circular=“true”,属性的静态绑定写法,不会变更

3) :autoplay=“autoplay”

vue中属性的动态绑定写法,绑定一个参数,参数值可根据界面操作(比如button、switch)变更

4) @scrolltolower=“lower”属性前加@

vue中动态绑定方法的写法

一、顶部banner图

/pages/article/article.vue

<template>
	<view class="u-p-l-10 u-p-r-10">
	  /**
		* class="article-swiper":样式为style中自定义的.article-swiper{...}
		* circular:是否采用衔接滑动
		* :autoplay="autoplay":是否自动切换,此处设置动态绑定autoplay参数
		* indicator-dots:是否显示面板展示点
		* duration="1000":滑动动画时长
		* 
		*/
		<swiper class="article-swiper" circular :autoplay="autoplay" indicator-dots duration="1000">
			/**
			* swiper下的每个swiper-item是一个滑动切换区域
			*/
			<swiper-item>
				
				<view class="article-swiper-item uni-bg-red">red</view>
			</swiper-item>
			<swiper-item>
				<view class="article-swiper-item uni-bg-green">green</view>
			</swiper-item>
			<swiper-item>
				<view class="article-swiper-item uni-bg-blue">blue</view>
			</swiper-item>
		</swiper>
		<view >
			<view>自动播放</view>
			/**
			 * switch 开关选择器
			 * :checked="autoplay":是否选中,由autoplay参数决定
			 * @change="changeAutoplay":checked改变时触发change事件,绑定changeAutoplay方法
			*/
				<switch :checked="autoplay" @change="changeAutoplay" />
			</view>
	</view>
</template>

<script>
	import config from "@/common/config.js"
	export default {
		data() {
			return {
				// 自动播放参数:默认值是true
				autoplay: true
			}
		},
		methods: {
			changeAutoplay(e) {
				// 点击时开关状态取反
			    this.autoplay = !this.autoplay
			}
		}
	}
</script>
<style lang="scss" scoped>
	.article-swiper {
		height: 300rpx;
	}
	
	.article-swiper-item {
		display: block;
		height: 300rpx;
		line-height: 300rpx;
		text-align: center;
	}
	
	.uni-bg-red {
		background-color: rgb(255, 85, 127);
	}
	
	.uni-bg-green {
		background-color: rgb(170, 255, 0);
	}
	
	.uni-bg-blue {
		background-color: rgb(85, 170, 255);
	}
</style>

二、静态按钮列表

/pages/article/article.vue

<template>
	<view class="u-p-l-10 u-p-r-10">
		<view>
			<view class="rowClass">
				<u-row>
				/**
				 * u-row、u-col:流式栅格系统,随着屏幕或视口分为 24 份,可以迅速简便地创建布局。
				 * span:定义u-col应该跨越的列数
				 * v-for="(item,index) in navList":列表渲染指令
				 *	(1) navList:data中的源数据数组
				 *  (2) item:data数据navList数组的别名
				 *  (3) index:navList数组的索引
				 * @tap="clickNav(item):方法暂未定义
				 *
				 * image:按钮图片
				 * item.name:静态按钮名称
				 */
					<u-col span="3" text-align="center" v-for="(item,index) in navList" :key="index">
						<view class="u-padding-20" @tap="clickNav(item)" hover-class="hoverClass">
							<image :src="item.src" style="width: 90rpx;height: 90rpx;" mode="widthFix"></image>
							<view class="tabName">{{item.name}}</view>
						</view>
					</u-col>
				</u-row>
			</view>
		</view>
	</view>
</template>
<script>
	import config from "@/common/config.js"
	export default {
		data() {
			return {
				navList:[
					{name:"发布文章",url:"pages/center/publishArticle"},
					{name:"我的文章",url:"pages/center/myArticle"},
					{name:"所有文章",url:"pages/center/allArticle"},
					{name:"浏览记录"}
				]
			}
		}
	}
</script>
<style lang="scss" scoped>
.rowClass{
		border-radius: 8px;
		background-color: rgb(255, 255, 255);
		margin-top: 10rpx;
		text-align: center;
	}
	
	.hoverClass{
		background-color: #E4E7ED;
	}

	.tabName{
		font-size: 28rpx;
		color: $u-main-color;
	}
</style>

三、横向滚动图

/pages/article/article.vue

<template>
	<view class="u-p-l-10 u-p-r-10">
		<view>
			<view >
				<text>滚动文章banner</text>
			</view>
			<view>
			/**
				 * :scroll-top="scrollTop":设置竖向滚动条位置
				 * scroll-y="true":允许纵向滚动
				 * show-scrollbar="true":是否出现滚动条,仅支持app-nvue
				 * @scrolltoupper="upper":滚动到顶部/左边,会触发 scrolltoupper 事件
				 * @scrolltolower="lower":滚动到底部/右边,会触发 scrolltolower 事件
				 * @scroll="scroll":滚动时触发
				 *
				 */
				<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" show-scrollbar="true" @scrolltoupper="upper"
					@scrolltolower="lower" @scroll="scroll" >
					<view id="demo1" class="scroll-view-item uni-bg-red">A</view>
					<view id="demo2" class="scroll-view-item uni-bg-green">B</view>
					<view id="demo3" class="scroll-view-item uni-bg-blue">C</view>
					
				</scroll-view>
			</view>
		</view>
	</view>
</template>
<script>
	import config from "@/common/config.js"
	export default {
		data() {
			return {
				scrollTop: 0,
				old: {
					scrollTop: 0
				}
			}
		},
		methods: {
			upper: function(e) {
				console.log(e)
			},
			lower: function(e) {
				console.log(e)
			},
			scroll: function(e) {
				console.log(e)
				this.old.scrollTop = e.detail.scrollTop
			}
		}
	}
</script>
<style lang="scss" scoped>
.uni-bg-red {
		background-color: rgb(255, 85, 127);
	}
	
	.uni-bg-green {
		background-color: rgb(170, 255, 0);
	}
	
	.uni-bg-blue {
		background-color: rgb(85, 170, 255);
	}
	
	.scroll-Y {
			height: 300rpx;
	}
	
	.scroll-view-item {
			height: 300rpx;
			line-height: 300rpx;
			text-align: center;
			font-size: 36rpx;
	}
</style>

四、动态列表 + 详情跳转

/pages/article/article.vue

<template>
	<view class="u-p-l-10 u-p-r-10">
		<view>
			<view >
				<text>滚动文章列表</text>
			</view>
			<view class="wrap">
				<scroll-view scroll-Y style="heignt: 100%;width 100%">
					<view>
					/**
					 * @click="clickContent(item):点击触发clickContent方法,跳转详情页面
					 */
						<view class="tabSwiper" v-for="(item,value) in articleList" :key="item.id" @click="clickContent(item)">
							<view class="top">
								<view class="left">
									<u-icon name="bell" :size="35" color="#2979ff"></u-icon>
									<view class="title">{{ item.title }}</view>
									<u-icon name="arrow-right" color="rgb(203,203,203)" :size="26"></u-icon>
								</view>
								
								<view class="right">{{ item.createTime }}</view>
							</view>
							<view class="item">
								<view class="content">
									<view class="title u-line-2">{{ item.content }}</view>
								</view>
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
	</view>
</template>
<script>
	import config from "@/common/config.js"
	export default {
		data() {
			return {
				pageNum:1,
				pageSize:50,
				articleList: [],
			}
		},
		onLoad() {
			this.getArticleList();
		},
		methods: {
			clickContent(item){
						if(item.id){
							this.$u.route('/pages/article/content', {
								id: item.id
							});
						}
			},
			getArticleList(){
				let url = "/api/cmsApi/findArticleList";
				this.$u.get(url,{
					pageNum:this.pageNum,
					pageSize:this.pageSize,
					orderByColumn:'create_time',
					isAsc:'desc'
				}).then(obj => {
					let data = obj.rows
					data.filter(item=>{
						this.articleList.push(
							{
								id:item.id,
								title: item.smallTitle,
								content: item.bigTitle,
								createTime: item.createTime
							}
						)
					})
				});
			}
		}
	}
</script>
<style lang="scss" scoped>
.tabSwiper {
		width: 710rpx;
		background-color: #ffffff;
		margin: 20rpx auto;
		border-radius: 20rpx;
		box-sizing: border-box;
		padding: 20rpx;
		font-size: 28rpx;
		.top {
			display: flex;
			justify-content: space-between;
			.left {
				display: flex;
				align-items: center;
				.title {
					margin: 0 10rpx;
					font-size: 32rpx;
					font-weight: bold;
				}
			}
			.right {
				color: $u-tips-color;
			}
		}
		.item {
			display: flex;
			margin: 20rpx 0 0;
			.left {
				margin-right: 20rpx;
				image {
					width: 200rpx;
					height: 200rpx;
					border-radius: 10rpx;
				}
			}
			.content {
				.title {
					font-size: 28rpx;
					line-height: 50rpx;
				}
			}
			.right {
				margin-left: 10rpx;
				padding-top: 20rpx;
				text-align: right;
			}
		}
	}
	
	.wrap {
		display: flex;
		flex-direction: column;
		height: calc(100vh - var(--window-top));
		width: 100%;
		
	}
</style>

五、详情页面

/pages/article/content.vue 添加详情页面的vue文件

<template>
	<view>
		<u-navbar :is-back="true" :title="title" :border-bottom="false"></u-navbar>
		<view class="u-content">
			<u-parse :html="content"
			:autosetTitle="true"
			:show-with-animation="true"
			:selectable="true"></u-parse>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title:'文章详情',
				content: ``
			}
		},
		onLoad(option) {
			let id = option.id
			let url = "/api/cmsApi/getArticle/"+id;
			this.$u.get(url).then(res => {
				this.title = res.data.smallTitle
				this.content = res.data.articleContent
			});
		},
	}
</script>

<style>
	page{
		background-color: #FFFFFF;
	}
</style>
<style lang="scss" scoped>
	.u-content{
		margin:0 10rpx;
		padding: 24rpx;
		font-size: 34rpx;
		color: $u-main-color;
		line-height: 1.8;
		white-space: pre-wrap !important;
	}
</style>

在pages.json添加文章详情页的的路由

{
	"pages": [// pages 设置页面路径及窗口表现
    //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
		{
     // pages节点的第一项为应用入口页(即首页)
			"path": "pages/index/index",
			"style": {
				"navigationStyle": "custom" ,// 导航栏样式:取消原生系统导航栏
				"navigationBarTitleText": "首页", // 导航栏标题文字
				"enablePullDownRefresh": true,  // 下拉刷新
				"app-plus": {
          // 编译到App平台的特定样式
					"pullToRefresh": {
            // 下拉刷新小圈圈样式
						"support": true,
						"color": "#2979ff", //小圈圈的颜色
						"style": "circle" //小圈圈的样式
					}
				}
			}
		},{
        	"path" : "pages/article/article",
        	"style" : 
        	{
				"navigationStyle": "custom" ,
        		"navigationBarTitleText" : "文章",
        		"enablePullDownRefresh" : true
        	}
        },
		{
			"path" : "pages/article/content",
			"style" : 
			{
				"navigationStyle": "custom" ,
				"navigationBarTitleText" : "文章详情",
				"enablePullDownRefresh" : true
			}
		}]
}

详情页效果如下
在这里插入图片描述

参考资料

uni-app官网

在此感谢@Ann_0207的技术支持!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1711949.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

大型跨境商城系统平台的技术架构分析

随着全球化的深入发展&#xff0c;大型跨境电商平台在如今的商业环境中扮演着越来越重要的角色。这些平台不仅仅是为了提供商品和服务&#xff0c;它们更是连接不同国家和地区消费者与供应商之间的桥梁。在这篇博客中&#xff0c;我们将深入探讨大型跨境商城系统平台的技术架构…

目标检测——家庭日常用品数据集

引言 亲爱的读者们&#xff0c;您是否在寻找某个特定的数据集&#xff0c;用于研究或项目实践&#xff1f;欢迎您在评论区留言&#xff0c;或者通过公众号私信告诉我&#xff0c;您想要的数据集的类型主题。小编会竭尽全力为您寻找&#xff0c;并在找到后第一时间与您分享。 …

7 Series FPGAs Integrated Block for PCI Express IP核设计中的物理层控制核状态接口

物理层控制和状态允许用户应用程序根据数据吞吐量和电源需求来更改链路的宽度和速度。 1 Design Considerations for a Directed Link Change 在Directed Link Change&#xff08;定向链接更改&#xff09;期间需要注意的事项有&#xff1a; 链接更改操作&#xff08;Link c…

加氢站压缩液驱比例泵放大器

加氢站压缩液驱液压系统的要求是实现换向和速度控制&#xff0c;对液压动力机构而言&#xff0c;按原理可区分为开式&#xff08;阀控&#xff09;- 节流控制系统和闭式&#xff08;泵控&#xff09;- 容积控制系统&#xff1a; 阀控系统 – 节流调速系统&#xff1a;由BEUEC比…

dp秒杀优惠券

1、全局id生成器 当用户抢购时&#xff0c;就会生成订单并保存到tb_voucher_order这张表中&#xff0c;而订单表如果使用数据库自增ID就存在一些问题&#xff1a; id的规律性太明显受单表数据量的限制 场景分析&#xff1a;如果我们的id具有太明显的规则&#xff0c;用户或者…

【机器学习】解锁AI密码:神经网络算法详解与前沿探索

&#x1f440;传送门&#x1f440; &#x1f50d;引言&#x1f340;神经网络的基本原理&#x1f680;神经网络的结构&#x1f4d5;神经网络的训练过程&#x1f686;神经网络的应用实例&#x1f496;未来发展趋势&#x1f496;结语 &#x1f50d;引言 随着人工智能技术的飞速发…

设计模式六大原则之依赖倒置原则

文章目录 概念逻辑关系 小结 概念 依赖倒置原则指在设计代码架构时&#xff0c;高层模块不应该依赖底层模块&#xff0c;二者都应该依赖抽象。抽象不应该依赖于细节&#xff0c;细节应该依赖于抽象。 逻辑关系 如上图所示&#xff0c;逻辑应该就是这样&#xff0c;高层依赖于…

深度学习-语言模型

深度学习-语言模型 统计语言模型神经网络语言模型语言模型的应用序列模型&#xff08;Sequence Model&#xff09;语言模型&#xff08;Language Model&#xff09;序列模型和语言模型的区别 语言模型&#xff08;Language Model&#xff09;是自然语言处理&#xff08;NLP&…

web自动化-数据驱动与失败用例截图、失败重新运行

因为只有失败的用例需要截图&#xff0c;那么问题就是&#xff1a; 什么时候用例会失败&#xff1f; 数据驱动测试 我们前面覆盖到的用例都是正常的用例&#xff0c;如果要测试异常的用例呢&#xff1f; 我们来写一下登录的异常 场景&#xff1a;【login_page】 # 用户输入框…

Adobe AntiCC 简化版 安装教程

Adobe AntiCC 简化版 安装教程 原文地址&#xff1a;https://blog.csdn.net/weixin_48311847/article/details/139277743

opencascade V3d_RectangularGrid 源码学习

类V3d_RectangularGrid V3d_RectangularGrid() V3d_RectangularGrid::V3d_RectangularGrid(const V3d_ViewerPointer &aViewer, const Quantity_Color &aColor, const Quantity_Color &aTenthColor) // 构造函数 ◆ ~V3d_RectangularGrid() virtual V3d_Rectang…

华为诺亚等发布MagicDrive3D:自动驾驶街景中任意视图渲染的可控3D生成

文章链接&#xff1a;https://arxiv.org/pdf/2405.14475 项目链接&#xff1a;https://flymin.github.io/magicdrive3d 虽然可控生成模型在图像和视频方面取得了显著成功&#xff0c;但在自动驾驶等无限场景中&#xff0c;高质量的3D场景生成模型仍然发展不足&#xff0c;主…

NDIS小端口驱动开发(三)

微型端口驱动程序处理来自过度驱动程序的发送请求&#xff0c;并发出接收指示。 在单个函数调用中&#xff0c;NDIS 微型端口驱动程序可以指示具有多个接收 NET_BUFFER_LIST 结构的链接列表。 微型端口驱动程序可以处理对每个NET_BUFFER_LIST结构上具有多个 NET_BUFFER 结构的多…

树莓派部署harbor_arm64

文章目录 树莓派4b部署Harbor-arm64版本docker-compose维护命令访问harbor 192.168.1.111认用户名密码admin/Harbor12345 树莓派4b部署Harbor-arm64版本 harbor-arm版本 部署&#xff1a;参考 wget https://github.com/hzliangbin/harbor-arm64/releases/download/v1.9.3/ha…

NFS p.1 服务器的部署以及客户端与服务端的远程挂载

目录 介绍 应用 NFS的工作原理 NFS的使用 步骤 1、两台机子 2、安装 3、配置文件 4、实验 服务端 准备 启动服务&#xff1a; 客户端 准备 步骤 介绍 NFS&#xff08;Network File System&#xff0c;网络文件系统&#xff09;是一种古老的用于在UNIX/Linux主…

redis数据类型之string,list

华子目录 key操作说明SCAN cursor [MATCH pattern] [COUNT count]dump与restorekeys 通配符 示例演示 string说明setbit key offset valuegetbit key offsetsetrange key offset value List结构图相关命令lrem key count valueltrim key count value示例&#xff1a;使用 LTRIM…

Blazor入门-svg绘制-碰撞检测和图形坐标调整

上一篇&#xff1a; Blazor入门-简单svg绘制导出图像_blazor 画图-CSDN博客 https://blog.csdn.net/pxy7896/article/details/139003443 注意&#xff1a;本文只给出思路和框架&#xff0c;对于具体的计算细节&#xff0c;考虑到日后会写入软件著作权和专利文书&#xff0c;因…

被追着问UUID和自增ID做主键哪个好,为什么?

之前无意间看到群友讨论到用什么做主键比较好 其实 UUID 和自增主键 ID 是常用于数据库主键的两种方式&#xff0c;各自具有独特的优缺点。 UUID UUID 是一个由 128 位组成的唯一标识符&#xff0c;通常以字符串形式表示。它可以通过不同的算法生成&#xff0c;例如基于时间…

绝招曝光!3小时高效利用ChatGPT写出精彩论文

在这份指南中&#xff0c;我将深入解析如何利用ChatGPT 4.0的高级功能&#xff0c;指导整个学术研究和写作过程。从初步探索研究主题&#xff0c;到撰写结构严谨的学术论文&#xff0c;我将一步步展示如何在每个环节中有效运用ChatGPT。如果您还未使用PLUS版本&#xff0c;可以…

C++入门 ros自定义msg话题通信

一、 开发环境 ubuntu20.04 ros版本noetic 参考视频 https://www.bilibili.com/video/BV1Ci4y1L7ZZ/?p52&spm_id_from333.1007.top_right_bar_window_history.content.click&vd_source4cd1b6f268e2a29a11bea5d2568836ee 二、 编写msg文件 在功能包下面创建msg文件夹…