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

uni-app x开发商城系统,商品详情轮播图,样式结构,数据渲染

一、概述

上一篇文章,已经实现了商品列表点击跳转至商品详情页

接下来实现,商品详情轮播图,样式结构,数据渲染

效果如下:

动画

二、商品详情轮播图

修改 pages/googs/goods-detail.uvue,新增轮播图

完整代码如下:

<template><view><view class="goods_detail"><!-- 轮播区域 --><view style="text-align: center;margin: 98px auto;color: red;" v-if="swipers.length==0">该商品暂未设置轮播图数据</view><up-swiper v-if="swipers.length>0" :list="swipers" keyName="src" indicator indicatorMode="dot"circular></up-swiper></view></view>
</template><script>export default {data() {return {//接收的idid: 0,//轮播图数据
                swipers: [],}},onLoad(value) {this.id = value.id;console.log("onload拿到商品id", this.id);//轮播图数据回显// this.getSwipers();
        },methods: {//获取轮播图数据
            async getSwipers() {const res = await this.$http.get('/api/getthumimages/' + this.id, {})this.swipers = res.message;console.log("详情页轮播图数据", this.swipers);},}}
</script><style lang="scss">.goods_detail {swiper {height: 700rpx;image {width: 100%;height: 100%;}}}
</style>

编译代码,效果如下:

image

 如果没有数据,会进行提示

image

三、商品详情样式结构

编辑 pages/googs/goods-detail.uvue,先固定一行数据

完整代码如下:

<template><view><view class="goods_detail"><!-- 轮播区域 --><view style="text-align: center;margin: 98px auto;color: red;" v-if="swipers.length==0">该商品暂未设置轮播图数据</view><up-swiper v-if="swipers.length>0" :list="swipers" keyName="src" indicator indicatorMode="dot"circular></up-swiper><!-- 商品详情 --><view class="box1"><view class="price"><text>¥5780</text><text>¥6388</text></view><view class="goods_name">华为(HUAWEI)荣耀6Plus 16G双4G版</view></view><view class="line"></view><view class="box2"><view>货号:SD721534532</view><view>库存:200</view></view><view class="line"></view><view class="box3"><view class="tit">详情介绍</view><view class="content" v-if="content!='undefined'"><!-- 支持富文本 --><rich-text :nodes="content"></rich-text></view><view style="text-align: center;color: red;" v-if="content.length==0">该商品暂无详情介绍数据</view></view></view></view>
</template><script>export default {data() {return {//接收的idid: 0,//轮播图数据
                swipers: [],//详情介绍content: "华为(HUAWEI),荣耀6Plus,移动/联通/电信/双4G版,双800万摄像头,八核,安卓智能手机,荣耀6plus",}},onLoad(value) {if (value.id != undefined) {this.id = value.id;console.log("onload拿到商品id", this.id);//轮播图数据回显
                this.getSwipers();}},methods: {//获取轮播图数据
            async getSwipers() {console.log("获取轮播图数据")const res = await this.$http.get('/api/getthumimages/' + this.id, {})this.swipers = res.message;console.log("详情页轮播图数据", this.swipers);},}}
</script><style lang="scss">.goods_detail {swiper {height: 700rpx;image {width: 100%;height: 100%;}}.box1 {padding: 10px;.price {display: flex;flex-direction: row; //横向排列font-size: 35rpx;color: $shop-color;line-height: 80rpx;// 原价样式 text:nth-child(2) {color: #ccc;font-size: 28rpx;margin-top: 5rpx;margin-left: 17rpx;text-decoration-line: line-through;}}.goods_name {font-size: 32rpx;line-height: 60rpx;}}.box2 {padding: 0 10px;font-size: 32rpx;line-height: 70rpx;}.box3 {padding-bottom: 50px;.tit {font-size: 32rpx;padding-left: 10px;border-bottom: 1px solid #eee;line-height: 70rpx;}.content {padding: 10px;font-size: 28rpx;color: #333;line-height: 50rpx;}}}.line {height: 10rpx;width: 750rpx;background: #eee;}
</style>

 

编译代码,效果如下:

image

四、数据渲染

修改 pages/googs/goods-detail.uvue,调用api接口

<template><view><view class="goods_detail"><!-- 轮播区域 --><view style="text-align: center;margin: 98px auto;color: red;" v-if="swipers.length==0">该商品暂未设置轮播图数据</view><up-swiper v-if="swipers.length>0" :list="swipers" keyName="src" indicator indicatorMode="dot" circular:height="uni.upx2px(700)"></up-swiper><!-- 商品详情 --><view class="box1"><view class="price"><text>¥{{goodsData.sell_price}}</text><text>¥{{goodsData.market_price}}</text></view><view class="goods_name">{{goodsData.title}}</view></view><view class="line"></view><view class="box2"><view>货号:{{goodsData.goods_no}}</view><view>库存:{{goodsData.stock_quantity}}</view></view><view class="line"></view><view class="box3"><view class="tit">详情介绍</view><view class="content" v-if="content!='undefined'"><!-- 支持富文本 --><rich-text :nodes="content"></rich-text></view><view style="text-align: center;color: red;" v-if="content.length==0">该商品暂无详情介绍数据</view></view></view></view>
</template><script>export default {data() {return {//接收的idid: 0,//轮播图数据
                swipers: [],//商品详细信息
                goodsData: [],//详情介绍content: "",}},onLoad(value) {if (value.id != undefined) {this.id = value.id;console.log("onload拿到商品id", this.id);//轮播图数据回显
                this.getSwipers();//商品详细信息
                this.getDetailInfo();//详情介绍数据
                this.getContent();}},methods: {//获取轮播图数据
            async getSwipers() {const res = await this.$http.get('/api/getthumimages/' + this.id, {})this.swipers = res.message;console.log("详情页轮播图数据", this.swipers);},//获取商品详细信息
            async getDetailInfo() {const res = await this.$http.get('/api/goods/getinfo/' + this.id, {})this.goodsData = res.message[0];console.log("商品数据信息", this.goodsData);},//获取详情介绍
            async getContent() {const res = await this.$http.get('/api/goods/getdesc/' + this.id, {})this.content = res.message[0].content;console.log("详情介绍数据", this.content);},}}
</script><style lang="scss">.goods_detail {swiper {height: 700rpx;image {width: 100%;height: 100%;}}.box1 {padding: 10px;.price {display: flex;flex-direction: row; //横向排列font-size: 35rpx;color: $shop-color;line-height: 80rpx;// 原价样式 text:nth-child(2) {color: #ccc;font-size: 28rpx;margin-top: 5rpx;margin-left: 17rpx;text-decoration-line: line-through;}}.goods_name {font-size: 32rpx;line-height: 60rpx;}}.box2 {padding: 0 10px;font-size: 32rpx;line-height: 70rpx;}.box3 {padding-bottom: 50px;.tit {font-size: 32rpx;padding-left: 10px;border-bottom: 1px solid #eee;line-height: 70rpx;}.content {padding: 10px;font-size: 28rpx;color: #333;line-height: 50rpx;img {width: 750rpx;}}}}.line {height: 10rpx;width: 750rpx;background: #eee;}
</style>

 编译代码,效果如下:

image

 

 详情介绍

image

 拖动到底部

image

最终效果如下:

动画

 

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

相关文章:

  • 机器学习经典算法——逻辑回归 - 实践
  • 095_尚硅谷_实现while和dowhile控制
  • 告别“功能堆砌陷阱”,2026年企业HR系统选型应聚焦价值而非价格
  • 线程和 Parallel.ForEach 的核心区别
  • 测试环境SQLSERVER数据库出现间歇性无法访问的问题
  • 2025年有实力的AI搜索优化品牌企业排行,专业AI搜索优化机构推荐
  • 2025年五大文物展柜制造企业推荐,文物展柜来样定制企业全解析
  • 2025年市面上锥芯板源头厂家排行榜前十强深度解析
  • 2025年市面上碳晶板品牌推荐排行榜前十强及行业洞察
  • 2025年四川桥架实力厂家排行榜前十强解析
  • 现今西南碳晶板制造厂技术评测与选择指南
  • 2025年成都锥芯板供应厂家排名前十:行业趋势与选择指南
  • 甩掉 “授权费包袱”!MyEMS:用开源技术让企业能源监控、分析、优化一步到位
  • MyEMS:不止是开源 EMS,更是企业降本、减碳、合规的 “全能工具包”
  • 2025年成都地铺石材厂家综合实力排行榜TOP10权威发布
  • keycloak~登录时将请求头里某个属性放入UserSessionModel
  • 2025年眼动仪提供商排行榜,眼动仪资深厂商公司推荐
  • 2026年放假安排
  • 【2025年11月】出国留学机构推荐:申请不同国家靠谱中介选择全攻略
  • 2025年11月市面上冷再生机实力厂家前十推荐榜单
  • TikTok 独立 IP 解决方案:独享静态住宅 IP + 环境隔离 + 粘性会话 - Smart
  • MyEMS 开源能源系统:解锁工业、园区、商业的双碳解题思路
  • 如何构建AI智能体:从理论到实践的全流程解析
  • 2025年照明灯具源头厂家推荐前十排行权威指南
  • 2025年成都照明灯具供应厂家排名前十推荐
  • 2025年11月冷再生机工厂前十推荐排行榜单:江苏环硕建设领跑行业
  • 2025年陕西省基本农田调整技术服务十大品牌权威排名
  • ARPO
  • 2025年热浸锌电缆桥架实力厂家权威推荐榜单:玻璃钢电缆桥架/镀锌电缆桥架/高分子电缆桥架源头厂家精选
  • 前端图片压缩方案