当前位置: 首页 > 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.zskr.cn/news/40852.html

相关文章:

  • 095_尚硅谷_实现while和dowhile控制
  • 甩掉 “授权费包袱”!MyEMS:用开源技术让企业能源监控、分析、优化一步到位
  • 2025年眼动仪提供商排行榜,眼动仪资深厂商公司推荐
  • 2026年放假安排
  • 【2025年11月】出国留学机构推荐:申请不同国家靠谱中介选择全攻略
  • TikTok 独立 IP 解决方案:独享静态住宅 IP + 环境隔离 + 粘性会话 - Smart
  • 如何构建AI智能体:从理论到实践的全流程解析
  • 前端图片压缩方案
  • 2025年西南电线电缆厂家综合实力排行榜TOP10
  • `__call__`使代码更Pythonic吗?
  • 20232414 2025-2026-1 《网络与系统攻防技术》实验四实验报告
  • 百度产品运营岗位--面试真题分析 - 教程
  • 【拾遗补漏】.NET 常见术语集
  • 四川腊肠腊肉烘干房厂家推荐:腊肠腊肉烘干房,专注风干鱼烘干房研发与生产,助力产业干燥需求
  • 2025进口艺术涂料厂家推荐榜:布雷诺,意大利进口艺术涂料厂家,从专业视角解锁墙面美学与品质之选
  • 接雨水问题反思与最大容器问题对比
  • 2025东莞餐桌滑轨厂家推荐榜:万利亨通,非标定制服务器滑轨厂家从家居到工业的优质选择指南
  • 2025年搪瓷管空气预热器厂家推荐榜:聊城九祥五星领跑,耐腐技术赋能工业节能升级
  • 详细介绍:学习Java第三十四天——黑马点评48~60
  • 2025.11
  • 英语_阅读_communication_待读
  • 实用指南:【MYSQL】SQL学习指南:从常见错误到高级函数与正则表达式
  • 2025年11月高压氧舱源头厂家哪家好专业指南
  • 打印机---重新安装驱动
  • 题解:P7468 [NOI Online 2021 提高组] 愤怒的小 N
  • MATLAB实现TDOA麦克风阵列声源定位
  • 2025年杭州专业代运营公司权威推荐榜单:直播代播/直播代运营/找电商代运营源头公司精选
  • 2025 最新推荐移民服务机构排行榜:精选靠谱中介,提供专业澳洲美国欧洲等国移民方案葡萄牙 / 新西兰 / 新加坡 / 投资 / 购房移民公司推荐
  • 结构(2)If语句和For循环
  • 2025 年工业风机厂家最新推荐排行榜:涵盖离心、高温、防腐、耐磨、防爆等类型设备实力厂商精选