自学内容网 自学内容网

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 标签,完美解决这个问题。


原文地址:https://blog.csdn.net/weixin_43659550/article/details/142219453

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!