html
<view> <!-- 搜索框 --> <u-search></u-search> <!-- 轮播图 --> <view class="lunbo"> <swiper indicator-dots autoplay circular interval="3000"> <swiper-item v-for="(item,index) in lunbo"> <image :src="'http://124.93.196.45:10001'+item.advImg"></image> </swiper-item> </swiper> </view> </view> <!-- 宫格图 --> <view class="server"> <u-grid col="5"> <u-grid-item v-for="(item,index) in server"> <image v-if="index<9" :src="'http://124.93.196.45:10001'+item.imgUrl"> </image> <text v-if="index<9">{{item.serviceName}}</text> <image v-if="index==9" src="../../static/uview/example/component.png"> </image> <text v-if="index==9">更多</text> </u-grid-item> </u-grid> </view> <!-- 热门主题 --> <view class="hot"> <view class="hot-tit">热门主题</view> <view class="hot-item"> <view class="item-pics" v-for="(item,index) in hotnews"> <image :src="'http://124.93.196.45:10001'+item.cover"></image> <view class="u-line-1">{{item.title}}</view> </view> </view> </view> <!-- 新闻专栏 --> <view class="news"> <view class="news-item">新闻专栏</view> <view class="category"> <view class="category-item" v-for="(item,index) in newcategory" @click="change(index)"> <view :class="active==index?'active':''">{{item.name}}</view> </view> </view> </view>
import api from '../../request/api.js' export default { data() { return { lunbo:[] } }, onLoad() { //开屏广告 uni.navigateTo({ url:'./home' }) //获取轮播图 this.getlunbo() }, methods: { //获取轮播图 async getlunbo(){ const params={ type:2 } const res = await api.Getlunbo(params) this.lunbo=res.data.rows // console.log(res) } //获取全部服务 async getserver() { const res1 = await api.Getserver() this.server = res1.data.rows // console.log(res1) } //获取热门主题 async gethot(){ const params={ hot:"Y" } const res2= await api.Getnews(params) this.hotnews=res2.data.rows console.log(res2) } //获取新闻分类 async getnewscategory(){ const res3=await api.Getnewscategory() this.newcategory=res3.data.data console.log(res3) }, change(index){ this.active=index } } }
.lunbo{ image{ width: 100%; height: 100%; } } /*全部服务*/ .server { margin-top: 10rpx; image { margin-top: 10rpx; width: 50rpx; height: 50rpx; } text { margin-top: 5rpx; font-size: 25rpx; } } /*热门主题*/ .hot{ .hot-tit{ margin: 20rpx; } .hot-item{ display: flex; .item-pics{ margin: 20rpx; width: 340rpx; image{ width:100%; border-radius:30rpx ; } } } } /*新闻专栏*/ .news{ .news-item{ margin:20rpx; } .category{ display: flex; font-size: 20rpx; .category-item{ width: 130rpx; text-align: center; height: 50rpx; border: 1rpx solid #eee; padding-top: 15rpx; border-radius:30rpx ; } } } .active{ color: #5ea9ff; }