1.創(chuàng)建一個公共目錄common來存放css和images
App.vue中引用
<style lang="scss">
?? ?/*每個頁面公共css */
? @import 'common/style/common-style.scss';
??
??
</style>
?
?2.渲染輪播圖
<template>
<view class="homeLayout">
<view class="banner">
<swiper indicator-dots indicator-color="rgba(255,255,255,0.5)"
indicator-active-color="#fff" autoplay
circular
>
<swiper-item v-for="item in 3" >
<image src="../../common/images/lxja.webp" mode="widthFix"></image>
</swiper-item>
</swiper>
</view>
</view>
</template>
<script setup>
</script>
<style lang="scss" scoped>
.homeLayout{
.banner{
width: 750rpx;
padding: 30rpx 0;
swiper{
width: 750rpx;
height: 340rpx;
// swiper-item{}
//簡化
&-item{
width: 100%;
height: 100%;
padding: 0 30rpx;
image{
width: 100%;
height: 100%;
border-radius: 10rpx;
}
}
}
}
}
</style>
3.公告的輪播
<view class="notice">
<view class="left">
<uni-icons type="sound-filled" size="20" color="#28b389"></uni-icons>
<text class="text">公告</text>
</view>
<view class="center">
<swiper vertical autoplay interval="1500" duration="300" circular>
<swiper-item v-for="item in 4">文字內(nèi)容文字內(nèi)容文字內(nèi)容文字內(nèi)容文字內(nèi)容文字內(nèi)容</swiper-item>
</swiper>
</view>
<view class="right">
<uni-icons type="right" size="16" color="#333"></uni-icons>
</view>
</view>
.notice{
width: 690rpx;
height: 80rpx;
line-height: 80rpx;
background: #f9f9f9;
margin: 0 auto;
border-radius: 80rpx;
display: flex;
.left{
width: 140rpx;
display: flex;
align-items: center;
justify-content: center;
.text{
color: #28b389;
font-weight: 600;
font-size: 28rpx;
}
}
.center{
flex: 1;
swiper{
height: 100%;
&-item{
height: 100%;
font-size: 30rpx;
color: #666;
//超出的文字用...替換
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
}
}
.right{
width: 70rpx;
display: flex;
align-items: center;
justify-content: center;
}
}
4.渲染公告下的內(nèi)容
創(chuàng)建公共標(biāo)題組件common-title
<view class="select">
<common-title></common-title>
<view class="content">
<scroll-view scroll-x>
<view class="box" v-for="item in 8">
<image src="../../common/images/lxja.webp" mode="aspectFill"></image>
</view>
</scroll-view>
</view>
</view>
將元素的
display
屬性設(shè)置為inline-block
可以讓元素既有行內(nèi)元素可以一行顯示多個的特性,又有塊級元素可以設(shè)置寬高的特性。?
?
.select{
padding-top: 50rpx;
.content{
width: 720rpx;
margin-left: 30rpx;
margin-top: 30rpx;
scroll-view{
white-space: nowrap;
.box{
width: 200rpx;
height: 430rpx;
display: inline-block;
margin-right: 15rpx;
image{
width: 100%;
height: 100%;
border-radius: 10rpx;
}
}
.box:last-child{
margin-right: 30rpx;
}
}
}
}
5.引入插槽定義公共標(biāo)題模塊
common-title
<template>
<view class="common-title">
<view class="name">
<!-- 插槽 -->
<slot name="name"></slot>
</view>
<view class="custom">
<slot name="custom"></slot>
</view>
</view>
</template>
<script setup>
</script>
<style lang="scss" scoped>
.common-title{
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 30rpx;
.name{
font-size: 40rpx;
}
}
</style>
index.vue
<view class="select">
<common-title>
<template #name>每日推薦</template>
<template #custom>
<view class="date">
<uni-icons type="calendar" size="18" color="#28b389"></uni-icons>
<view>
<uni-dateformat :date="Date.now()" format="dd日"></uni-dateformat>
</view>
</view>
</template>
</common-title>
<view class="content">
<scroll-view scroll-x>
<view class="box" v-for="item in 8">
<image src="../../common/images/lxja.webp" mode="aspectFill"></image>
</view>
</scroll-view>
</view>
</view>
<view class="theme">
<common-title>
<template #name>專題精選</template>
<template #custom>
<navigator url="" class="more">More+</navigator>
</template>
</common-title>
</view>
6.渲染專題精選
?index.vue
<view class="theme">
<common-title>
<template #name>專題精選</template>
<template #custom>
<navigator url="" class="more">More+</navigator>
</template>
</common-title>
<view class="content">
<theme-item v-for="item in 8"></theme-item>
</view>
</view>
?
.theme{
? ? ? ? padding-top: 50rpx;
? ? ? ? .more{
? ? ? ? ? font-size: 32rpx;
? ? ? ? ? color: #888;
? ? ? ? }
? ? ? ? .content{
? ? ? ? ? margin-top: 30rpx;
? ? ? ? ? padding: 0 30rpx;
? ? ? ? ? //網(wǎng)格布局
? ? ? ? ? display: grid;
? ? ? ? ? //每個元素中間有一個間隙
? ? ? ? ? gap: 15rpx;
? ? ? ? ? //一行展示三個每行平均分配
? ? ? ? ? grid-template-columns: repeat(3,1fr);
? ? ? ? }
? ? }
新創(chuàng)建一個組件them-item
<template>
<view class="themeTtem">
<navigator url="" class="box">
<image class="pic" src="https://img1.baidu.com/it/u=871832137,2572636834&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=1198" mode="aspectFill"></image>
<view class="mask">盛世美顏</view>
<view class="tab">3天前更新</view>
</navigator>
</view>
</template>
.themeTtem{
? .box{
? ? height: 340rpx;
? ? border-radius: 10rpx;
? ? //不加overflow:圓角顯示不出來
? ? overflow: hidden;
? ? position: relative;
? ? .pic{
? ? ? width: 100%;
? ? ? height: 100%;
? ? }
? ? .mask{
? ? ? width: 100%;
? ? ? height: 70rpx;
? ? ? position: absolute;
? ? ? bottom: 0;
? ? ? left: 0;
? ? ? //磨砂透明
? ? ? background: rgba(0,0,0,0.2);
? ? ? color: #fff;
? ? ? display: flex;
? ? ? align-items: center;
? ? ? justify-content: center;
? ? ? //模糊濾鏡
? ? ? backdrop-filter: blur(20rpx);
? ? ? font-weight: 600;
? ? ? font-size: 30rpx;
? ? }
? ? .tab{
? ? ? position: absolute;
? ? ? left: 0;
? ? ? top: 0;
? ? ? background: rgba(250,129,90,0.7);
? ? ? backdrop-filter: blur(20rpx);
? ? ? color: #fff;
? ? ? font-size: 22rpx;
? ? ? padding: 6rpx 14rpx;
? ? ? //左上 右上 右下 ?左下
? ? ? border-radius: 0 0 20rpx 0;
? ? ? //網(wǎng)格文字最小為12px,要想小于12px,可進行如下操作
? ? ? //縮放
? ? ? transform: scale(0.8);
? ? ? //以左上角基準(zhǔn)偏移
? ? ? transform-origin: left top;
? ? }
? }
}
?
1)渲染更多標(biāo)題
index.vue
?<view class="theme">
? ? ? ? ? <common-title>
? ? ? ? ? ? <template #name>專題精選</template>
? ? ? ? ? ? <template #custom>
? ? ? ? ? ? ? <navigator url="" class="more">More+</navigator>
? ? ? ? ? ? </template>
? ? ? ? ? </common-title>
? ? ? ? ? <view class="content">
? ? ? ? ? ? ? <theme-item v-for="item in 8"></theme-item>
? ? ? ? ? ? ? <theme-item :isMore="true"></theme-item>
? ? ? ? ? </view>
? ? ? </view>
?them-item
?<view class="themeTtem">
? ? ? <navigator url="" class="box" v-if="!isMore">
? ? ? ? <image class="pic" src="https://img1.baidu.com/it/u=871832137,2572636834&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=1198" mode="aspectFill"></image>
? ? ? ? <view class="mask">盛世美顏</view>
? ? ? ? <view class="tab">3天前更新</view>
? ? ? </navigator>
? ? ? <navigator url="" class="box more" v-else>
? ? ? ? <image class="pic" src="https://img1.baidu.com/it/u=351608013,944758287&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=751" mode="aspectFill"></image>
? ? ? ? <view class="mask">
? ? ? ? ? <uni-icons type="more-filled" size="34" color="#fff"></uni-icons>
? ? ? ? ? <view class="text">更多</view>
? ? ? ? </view>
? ? ? </navigator>
? </view>文章來源:http://www.zghlxwxcb.cn/news/detail-844742.html
.box.more{
? ? .mask{
? ? ? width: 100%;
? ? ? height: 100%;
? ? ? flex-direction: column;
? ? }
? ? .text{
? ? ? font-size: 28rpx;
? ? }
? }文章來源地址http://www.zghlxwxcb.cn/news/detail-844742.html
到了這里,關(guān)于壁紙小程序Vue3(首頁布局)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!