当前位置: 首页 > article >正文

EP12 分类列表元素点击跳转

文件路径: E:/homework/uniappv3tswallpaper/pages.json

{
	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
		{
			"path": "pages/index/index",
			"style": {
				"navigationBarTitleText": "uni-app",
				"navigationStyle": "custom"
			}
		},
		{
			"path": "pages/classify/classify",
			"style": {
				"navigationBarTitleText": "classify",
				"navigationStyle": "custom"
			}
		},
		{
			"path": "pages/user/user",
			"style": {
				"navigationBarTitleText": "user",
				"navigationStyle": "custom"
			}
		},
		{
			"path": "pages/classlist/classlist",
			"style": {
				"navigationBarTitleText": "classlist",
				"navigationStyle": "custom"
			}
		}
	],
	"globalStyle": {
		"navigationBarTextStyle": "black",
		"navigationBarTitleText": "壁纸",
		"navigationBarBackgroundColor": "#fff",
		"backgroundColor": "#F8F8F8"
	},
	"tabBar": {
		"color": "#9799a5",
		"selectedColor": "#28B389",
		"list": [{
			"text": "分类",
			"pagePath": "pages/classify/classify",
			"iconPath": "static/images/tabBar/classify.png",
			"selectedIconPath": "static/images/tabBar/classify-h.png"
		}, {
			"text": "推荐",
			"pagePath": "pages/index/index",
			"iconPath": "static/images/tabBar/home.png",
			"selectedIconPath": "static/images/tabBar/home-h.png"
		}, {
			"text": "我的",
			"pagePath": "pages/user/user",
			"iconPath": "static/images/tabBar/user.png",
			"selectedIconPath": "static/images/tabBar/user-h.png"
		}]
	},
	"uniIdRouter": {}
}

给每个 tabbar 中的页面添加上 navigationStyle 属性。

文件路径: E:/homework/uniappv3tswallpaper/components/theme-item/theme-item.vue

<template>
	<view class="themeItem">
		<navigator url="/pages/classlist/classlist" class="box" v-if="!isMore">
			<image class="pic" src="../../common/images/classify1.jpg" mode="aspectFill"></image>
			<view class="mask">
				明星美女
			</view>
			<view class="tab">
				3天前更新
			</view>
		</navigator>
		<navigator url="/pages/classify/classify" open-type="reLaunch" class="box more" v-if="isMore">
			<image class="pic" src="../../common/images/more.jpg" mode="aspectFill"></image>
			<view class="mask">
				<uni-icons type="more-filled" size="34" color="#fff"></uni-icons>
				<view class="text">
					更多
				</view>
			</view>
		</navigator>
	</view>
</template>

<script setup>
	defineProps({
		isMore: {
			type: Boolean,
			default: false
		}
	})
</script>

<style lang="scss">
	.themeItem {
		.box {
			height: 340rpx;
			border-radius: 10rpx;
			overflow: hidden;
			position: relative;

			.pic {
				width: 100%;
				height: 100%;
			}

			.mask {
				position: absolute;
				bottom: 0;
				left: 0;
				width: 100%;
				height: 70rpx;
				background-color: rgba(0, 0, 0, 0.2);
				color: #fff;
				display: flex;
				align-items: center;
				justify-content: center;
				font-weight: 600;
				backdrop-filter: blur(20rpx);
			}

			.tab {
				position: absolute;
				left: 0%;
				top: 0%;
				background: rgba(250, 190, 90, 0.7);
				backdrop-filter: blur(20rpx);
				color: #fff;
				padding: 6rpx 14rpx;
				border-radius: 0 0 20rpx 0;
				transform: scale(0.8);
				transform-origin: left top;
			}
		}

		.box.more {

			.mask {
				height: 100%;
				width: 100%;
				flex-direction: column;
			}

			.text {
				font-size: 28rpx;
			}
		}
	}
</style>

分类页面中的每一项都是全局组件 theme-item ,所以在组件上直接添加 url

并且 more 组件中的跳转目标页面同样是 tabbar 中的页面,所以需要添加 open-type 属性。

文件路径: E:/homework/uniappv3tswallpaper/pages/user/user.vue

<template>
	<view class="userLayout pageBg">
		<view class="userInfo">
			<view class="avatar">
				<image src="../../common/images/preview1.jpg" mode="aspectFill"></image>
			</view>
			<view class="ip">
				100.100.100.100
			</view>
			<view class="from">
				中国山东
			</view>
		</view>
		<view class="section">
			<view class="list">
				<navigator url="/pages/classlist/classlist">
					<view class="row">
						<view class="left">
							<uni-icons type="download-filled" size="20" color="#28b389"></uni-icons>
							<view class="text">
								我的下载
							</view>
						</view>
						<view class="right">
							<view class="text">
								33
							</view>
							<uni-icons type="right" size="15" color="#aaa"></uni-icons>
						</view>
					</view>
				</navigator>
				<navigator url="/pages/classlist/classlist">
					<view class="row">
						<view class="left">
							<uni-icons type="star-filled" size="20" color="#28b389"></uni-icons>
							<view class="text">
								我的评分
							</view>
						</view>
						<view class="right">
							<view class="text">
								33
							</view>
							<uni-icons type="right" size="15" color="#aaa"></uni-icons>
						</view>
					</view>
				</navigator>
				<view class="row">
					<view class="left">
						<uni-icons type="chatboxes-filled" size="20" color="#28b389"></uni-icons>
						<view class="text">
							联系客服
						</view>
					</view>
					<view class="right">
						<view class="text">
						</view>
						<uni-icons type="right" size="15" color="#aaa"></uni-icons>
					</view>
					<!-- #ifdef MP -->
					<button open-type="contact">联系客服</button>
					<!-- #endif -->
					<!-- #ifndef MP -->
					<button @click="clickContact">打电话</button>
					<!-- #endif -->
				</view>
			</view>
		</view>
		<view class="section">
			<view class="list">
				<view class="row">
					<view class="left">
						<uni-icons type="notification-filled" size="20" color="#28b389"></uni-icons>
						<view class="text">
							订阅更新
						</view>
					</view>
					<view class="right">
						<view class="text">

						</view>
						<uni-icons type="right" size="15" color="#aaa"></uni-icons>
					</view>
				</view>
				<view class="row">
					<view class="left">
						<uni-icons type="flag-filled" size="20" color="#28b389"></uni-icons>
						<view class="text">
							常见问题
						</view>
					</view>
					<view class="right">
						<view class="text">

						</view>
						<uni-icons type="right" size="15" color="#aaa"></uni-icons>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	const clickContact = () => {
		uni.makePhoneCall({
			phoneNumber: '114' //仅为示例
		});
	}
</script>

<style lang="scss" scoped>
	.userLayout {
		.userInfo {
			display: flex;
			flex-direction: column;
			flex-wrap: nowrap;
			align-content: center;
			justify-content: center;
			align-items: center;
			padding: 50rpx 0;

			.avatar {
				height: 160rpx;
				width: 160rpx;
				border-radius: 50%;
				overflow: hidden;

				image {
					height: 100%;
					width: 100%;
				}
			}

			.ip {
				font-size: 44rpx;
				color: #333;
				padding: 20rpx 0 5rpx;
			}

			.from {
				font-size: 28rpx;
				color: #aaa;
			}

		}
	}

	.section {
		width: 690rpx;
		margin: 50rpx auto;
		border: 1rpx solid #eee;
		border-radius: 10rpx;
		border-shadow: 0 0 30rpx rgba(0, 0, 0, 0.2);

		.list {
			.row {
				display: flex;
				flex-direction: row;
				flex-wrap: nowrap;
				align-content: center;
				justify-content: space-between;
				align-items: center;
				padding: 0 30rpx;
				height: 100rpx;
				border-bottom: 1px solid #eee;
				position: relative;
				background: white;

				:last-child {
					border-bottom: 0;
				}

				.left {
					display: flex;
					flex-direction: row;
					flex-wrap: nowrap;
					align-content: center;
					align-items: center;

					.text {
						padding-left: 20rpx;
						color: #666
					}
				}

				.right {
					display: flex;
					flex-direction: row;
					flex-wrap: nowrap;
					align-content: center;
					align-items: center;

					.text {
						padding-left: 20rpx;
						color: #666
					}
				}

				button {
					position: absolute;
					top: 0%;
					left: 0%;
					height: 100%;
					width: 100%;
					opacity: 0
				}
			}
		}
	}
</style>

user 页面中也有需要跳转到详情列表页面的情况。

文件路径: E:/homework/uniappv3tswallpaper/pages/classlist/classlist.vue

<template>
	<view class="classlist">
		<view class="content">
			<navigator url="" class="item" v-for="item in 10">
				<image src="../../common/images/preview2.jpg" mode="aspectFill"></image>
			</navigator>
		</view>
	</view>
</template>

<script setup>

</script>

<style lang="scss">
	.classlist {
		.content {
			display: grid;
			grid-template-columns: repeat(3, 1fr);
			gap: 5px;
			padding: 5rpx;

			.item {
				height: 440rpx;
				width: 100%;

				image {
					height: 100%;
					width: 100%;
					display: block;
				}
			}
		}
	}
</style>

详情列表页面单独写成一个页面。

注意:
user 页面中实现跳转的时候,如果将元素的 view 标签改为 navigator 标签,可能会因为 navigator 标签的内置 a 标签而造成布局错乱。
可以在 view 标签外层直接套用 navigator 标签,完美解决这个问题。


http://www.kler.cn/a/307342.html

相关文章:

  • arcgis做buffer
  • 基于OpenCV的自制Python访客识别程序
  • 封装一个省市区的筛选组件
  • HBase使用create创建表时报错ERROR: KeeperErrorCode = NoNode for /hbase/master
  • 阿里云和七牛云对象存储区别和实现
  • 45.第二阶段x86游戏实战2-hook监控实时抓取游戏lua
  • 【云原生监控】Prometheus之PushGateway
  • 机器学习的入门指南
  • JVM HotSpot 虚拟机: 对象的创建, 内存布局和访问定位
  • Oracle数据库中的归档日志(Archive Log)详解与应用
  • 07_Python数据类型_集合
  • 系统 IO
  • 08_Python数据类型_字典
  • C# 记录一个获取系统空闲时间的函数,可用于判断休眠
  • 性能测试:Locust使用介绍(三)
  • MoCo对比损失
  • LC并联电路在正弦稳态下的传递函数推导(LC并联谐振选频电路)
  • 带你如何使用CICD持续集成与持续交付
  • 2024网络安全、应用软件系统开发决赛技术文件
  • Go语言现代web开发15 泛型和错误
  • C++中string字符串类型介绍及数组模拟
  • TDengine 与 SCADA 强强联合:提升工业数据管理的效率与精准
  • 如何在 Ubuntu 系统上部署 Laravel 项目 ?
  • 基于JavaWeb开发的Java+SpringMvc+vue+element实现上海汽车博物馆平台
  • [NSSRound#4 SWPU]hide_and_seek-用gdb调试
  • 美团图床设置教程