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

uni-app x开发商城系统,社区图片,左侧结构样式,数据渲染,点击高亮

一、概述

上一篇文章,已经实现了联系我们,地图显示,拨打电话。

接下来,实现社区图片,左侧结构样式,效果如下:

二、scroll-view

可滚动视图区域。用于区域滚动。

官方文档:https://uniapp.dcloud.net.cn/component/scroll-view.html

修改 pages/pics/pics.uvue文件,增加view

完整代码如下:

<template><view class="pics"><!-- 左侧分类 --><scroll-view class="left" style="width: 200rpx;height: 100vh;border-right: 1px solid #eee;" scroll-y="true"><view v-for="index in 20" :key="index" :class="index==1?'active':''">家居生活 {{index}}</view></scroll-view></view>
</template><script>export default {data() {return {}},methods: {}}
</script><style lang="scss">page {display: flex;height: 100%;}.pics {height: 100%;display: flex;.left {view {height: 60px;line-height: 60px;color: #333;text-align: center;font-size: 30rpx;border-top: 1px solid #eee;}.active {background: $shop-color;color: #fff;}}}
</style>

说明:

scroll-y="true",允许纵向滚动

view做了一下for循环,模拟2个分类。

:class="index==1?'active':''",表示第一个高亮显示。

 

编译运行,效果如下:

动画

可以看到左侧区域,能上下滑动。

三、数据渲染

左侧展示的分类是固定的,接下来需要调用api接口,渲染数据

修改 pages/pics/pics.uvue文件,调用api

完整代码如下:

<template><view class="pics"><!-- 左侧分类 --><scroll-view class="left" style="width: 200rpx;height: 100vh;border-right: 1px solid #eee;" scroll-y="true"><view v-for="(item,index) in picCates" :key="item.id" :class="index==1?'active':''">{{item.title}}</view></scroll-view></view>
</template><script>export default {data() {return {picCates: [],}},onLoad() {this.getPicsList()},methods: {// 获取图片分类
            async getPicsList() {try {const res = await this.$http.get('/api/getimgcategory', {})// console.log("分类列表数据", res.message);// 分类数据回显this.picCates = res.message;} catch (err : any) {console.log("err", err)uni.showToast({title: '获取图片分类失败' + err.statusCode,});}},}}
</script><style lang="scss">page {display: flex;height: 100%;}.pics {height: 100%;display: flex;.left {view {height: 60px;line-height: 60px;color: #333;text-align: center;font-size: 30rpx;border-top: 1px solid #eee;}.active {background: $shop-color;color: #fff;}}}
</style>

说明:

这里定义了一个方法getPicsList,获取图片分类数据,然后使用for循环遍历。

 

编译运行,效果如下:

image

四、 点击高亮

接下来需要实现,点击哪个分类,就高亮显示。

修改 pages/pics/pics.uvue文件,增加点击事件,class动态判断

<template><view class="pics"><!-- 左侧分类 --><scroll-view class="left" style="width: 200rpx;height: 100vh;border-right: 1px solid #eee;" scroll-y="true"><view v-for="(item,index) in picCates" :key="item.id" :class="active==index?'active':''"@click="leftCliclActive(index,item.id)">{{item.title}}</view></scroll-view></view>
</template><script>export default {data() {return {//分类数据
                picCates: [],//选中高亮 默认0,判断+1active: 0,}},onLoad() {this.getPicsList()},methods: {// 获取图片分类
            async getPicsList() {try {const res = await this.$http.get('/api/getimgcategory', {})// console.log("分类列表数据", res.message);// 分类数据回显this.picCates = res.message;} catch (err : any) {console.log("err", err)uni.showToast({title: '获取图片分类失败' + err.statusCode,});}},//点击分类设置为activeasync leftCliclActive(index, id) {console.log("点击的分类下标:", index, "id:", id);this.active = index;},}}
</script><style lang="scss">page {display: flex;height: 100%;}.pics {height: 100%;display: flex;.left {view {height: 60px;line-height: 60px;color: #333;text-align: center;font-size: 30rpx;border-top: 1px solid #eee;}.active {background: $shop-color;color: #fff;}}}
</style>

 说明:

leftCliclActive,点击分类设置为active,需要传递2个参数

active,这个是在data里面定义的,用来判断是否高亮显示。

:class="active==index?'active':'',根据点击的索引值进行判断,是否增加高亮显示的样式。

 

 编译运行,效果如下:

动画

 

 

 
http://www.jsqmd.com/news/27706/

相关文章:

  • Nginx的请求处理
  • 2025年液相色谱仪口碑推荐优质厂家,国产仪器品牌哪家强?
  • 【MySQL】数据库基础 - 详解
  • 云湖+小马算力:无需懂技术,轻松知识库AI智能机器人
  • 2025年深圳geo优化服务公司权威推荐榜单:geo优化公司/geo优化推广/ai排名优化源头公司精选
  • 2025年架空电缆源头厂家权威推荐榜单:屏蔽电缆/防火电缆/矿物质电缆源头厂家精选
  • hello-gui
  • 异常的处理
  • 银河麒麟服务器操作系统 V10 (Lance) 安装docker 28
  • Python创建类(下)_ 当上帝的时刻到了
  • 超纯水售后哪家好?国产仪器权威推荐品牌top2
  • PADS丨极坐标设置
  • 题解:P11630 [WC2025] 士兵
  • 2025 年 SMT 加工优质厂家最新推荐榜,技术实力与市场口碑深度解析的权威甄选结果
  • Oracle 19c数据库迁移到IvorySQL 4.6实战
  • 2025 年 10 月北京清洗公司最新推荐,聚焦资质、案例、售后的五家机构深度解读
  • 2025年仪器计量制造企业权威推荐榜单:计量检测服务/仪器类检测/计量检测源头厂家精选
  • 紫外分光光度计哪家好?TOP1品牌权威推荐,选购建议看这里!
  • 2025年网络隔离变压器优质厂家权威推荐榜单:以太网变压器/数据泵/网络变压器源头厂家精选
  • 2025 年提升门厂家最新推荐榜,技术实力与市场口碑深度解析,筛选优质品牌助力采购决策
  • 2025 年杭州画室推荐:之江画室以央清班十年口碑、突出设计学录取案例与优质教学空间立足行业
  • 框架工具
  • nvm pnpm conda python 多版本管理器
  • PADS丨Logic 快速批量设置带有页间连接符的网络名
  • ubuntu 22 vnc
  • rlwrap 安装
  • langfuse docker 镜像构建
  • hello-白噪音
  • 测试用例覆盖率
  • 2025 工业加热器选型必看:六大加热器实力厂家深度推荐,覆盖多场景加热设备解决方案