当前位置:网站首页>[applet project development -- JD mall] product list page of uni app (Part 1)
[applet project development -- JD mall] product list page of uni app (Part 1)
2022-07-18 22:35:00 【Computer magician】

Welcome to
Magic house !!The article contains columns
2022 Wechat applet Jingdong Mall actual battleColumn content
Jingdong Mall uni-app Project structures,
Jingdong Mall uni-app To configure tabBar & Window style
Jingdong Mall uni-app Developed subcontracting configuration
Jingdong Mall uni-app Developed rotation chart
Jingdong Mall uni-app The classified navigation area
Jingdong Mall uni-app Home floor products
Jingdong Mall uni-app Product classification page ( On )
Jingdong Mall uni-app Product classification page ( Next )
Jingdong Mall uni-app Custom search component ( On )
Jingdong Mall uni-app Custom search component ( in )
Jingdong Mall uni-app Custom search component ( Next ) – Search history
List of articles
- One 、 Introduction
- Two 、 establish goodlist Branch ( the selected readings *)
- 3、 ... and 、 Product list search data request
- Four 、 Call the interface to get the list data
- 5、 ... and 、 Render the product list page
- 6、 ... and 、 Put the goods item Components are encapsulated as custom components
- 7、 ... and 、 Use filters to process commodity prices
One 、 Introduction
There are mainly three ways to enter the product page
- Click on the commodity floor ( The ginseng
queryInquire about ) - Click on the classification page ( The ginseng
cidclassification ) - Click on the search page ( The ginseng
queryInquire about )
Add product page compilation mode
Two 、 establish goodlist Branch ( the selected readings *)
git checkout -b goodlist

3、 ... and 、 Product list search data request
Product list search
Request path :https:// Request domain name /api/public/v1/goods/search
Request method :GET
Request parameters
| Parameter name | Parameter description | remarks |
|---|---|---|
| query | Search keywords | |
| cid | classification ID | Optional |
| pagenum | Page index | Optional default first page |
| pagesize | Length of each page | Optional default 20 strip |
- The response data
{
"message": {
"total": 2058,
"pagenum": "1",
"goods": [
{
"goods_id": 57332,
"cat_id": 998,
"goods_name": "400 ml Seafood frozen ice packs Water filled ice bags, medical ice bags, outdoor cold storage, fresh preservation, cold storage of cooked food, repeated use (10 Individual outfit )",
"goods_price": 14,
"goods_number": 100,
"goods_weight": 100,
"goods_big_logo": "http://image4.suning.cn/uimg/b2c/newcatentries/0070083251-000000000168369396_1_800x800.jpg",
"goods_small_logo": "http://image4.suning.cn/uimg/b2c/newcatentries/0070083251-000000000168369396_1_400x400.jpg",
"add_time": 1516662792,
"upd_time": 1516662792,
"hot_mumber": 0,
"is_promote": false,
"cat_one_id": 962,
"cat_two_id": 981,
"cat_three_id": 998
},
{
"goods_id": 57194,
"cat_id": 992,
"goods_name": " Yili car washing tools, car beauty products, sponge brush, no damage to the car paint, wipe the car, sponge cleaning sponge ",
"goods_price": 29,
"goods_number": 100,
"goods_weight": 100,
"goods_big_logo": "",
"goods_small_logo": "",
"add_time": 1516662312,
"upd_time": 1516662312,
"hot_mumber": 0,
"is_promote": false,
"cat_one_id": 962,
"cat_two_id": 980,
"cat_three_id": 992
}
]
},
"meta": {
"msg": " To be successful ",
"status": 200
}
}
- data Define data storage parameters
<script>
export default {
data() {
return {
title:'',
// queryobject
queryObj: {
query: '',
cid:"",
// page
pagenum: 1,
// Number of data
pagesize: 10
}
};
},
onLoad(options){
console.log(options)
this.title = options.name
this.queryObj.query = options.query || ''
this.queryObj.cid = options.cat_id || ''
},
Four 、 Call the interface to get the list data
- data Define data storage
- onload The load function
- Define the data retrieval function
<script>
export default {
data() {
return {
goodlist: [],
// Total number of goods
total: 0
};
},
onLoad(options){
this.getGoodlist()
},
methods: {
async getGoodlist(){
const {
data:res} = await uni.$http.get('/api/public/v1/goods/search',this.queryObj)
console.log(res)
if (res.meta.status != 200) return uni.$showMsg(" Data retrieval failed ")
this.goodlist = res.message.goods
this.total = res.message.total
}
}
5、 ... and 、 Render the product list page
- Because some pictures cannot be displayed , Define a default picture
// The default image
defaultimg: "your image url"
- wxml structure
<template>
<view>
<!-- List of pp. -->
<view class="goods-list">
<view class="good-item">
<block v-for="(item,i) in goodlist" v-bind:key="i">
<!-- Left box -->
<view class="good-item-left">
<!-- If not, use the default picture -->
<image :src="item.goods_big_logo || defaultimg" mode=""></image>
</view>
<!-- Right side box -->
<view class="good-item-right">
<view class="good-item-name">{
{
item.goods_name}}</view>
<view class="good-item-info">
<view class="good-price">¥ {
{
item.goods_price}}</view>
</view>
</view>
</block>
</view>
</view>
</view>
</template>
- effect

- Style beautification
<style lang="scss">
.goods-list {
.good-item {
display: flex;
border-bottom: 2px solid #f1f1f1;
.good-item-left {
image {
height: 200rpx;
width: 200rpx;
display: block;
}
padding: 20rpx;
}
.good-item-right {
display: flex;
flex-direction: column;
justify-content: space-between;
padding: 20rpx;
.good-item-name {
font-size: 14px;
}
.good-item-info {
.good-price {
font-size: 16px;
color: #c00000;
}
}
}
}
}
</style>
- effect :

6、 ... and 、 Put the goods item Components are encapsulated as custom components
stay component Create under file my_goods Components

Migrate the corresponding structure and style
<template>
<view>
<view class="good-item">
<!-- Left box -->
<view class="good-item-left">
<!-- If not, use the default picture -->
<image :src="good.goods_big_logo || defaultimg" mode=""></image>
</view>
<!-- Right side box -->
<view class="good-item-right">
<view class="good-item-name">{
{good.goods_name}}</view>
<view class="good-item-info">
<view class="good-price">¥ {
{good.goods_price}}</view>
</view>
</view>
</view>
</view>
</template>
<script> export default {
name: "my-goods", props: {
good: {
type: Object, default: {
} } }, data() {
return {
// The default image defaultimg: "https://ts1.cn.mm.bing.net/th/id/R-C.e74289455bec048b0ba2feb90e3b74f2?rik=fYpAtit%2bc2W4ZA&riu=http%3a%2f%2fimage.woshipm.com%2fwp-files%2f2017%2f04%2ftAd0ldHk60s3GAI6TNqd.jpg&ehk=RWuC%2f9spxWPWcW3w4axPrb3YP9Nt3JXlajvJWKRXV5k%3d&risl=&pid=ImgRaw&r=0" }; } } </script>
<style lang="scss"> .good-item {
display: flex; border-bottom: 2px solid #f1f1f1; .good-item-left {
image {
height: 200rpx; width: 200rpx; display: block; } padding: 20rpx; } .good-item-right {
display: flex; flex-direction: column; justify-content: space-between; padding: 20rpx; .good-item-name {
font-size: 14px; } .good-item-info {
.good-price {
font-size: 16px; color: #c00000; } } } } </style>
7、 ... and 、 Use filters to process commodity prices
Let the commodity price be displayed with a decimal point
- Definition filter
filters: {
tofixed(num){
// Returns a two digit value
return Number(num).toFixed(2)
}
},
- Use filters
<view class="good-price">¥ {
{
good.goods_price | tofixed }}</view>
- effect

Come here , If there are any questions
Welcome private bloggers to ask questions , Bloggers will do their best to answer your doubts !
🥳 If it helps you , Your praise is the greatest support for bloggers !!🥳
边栏推荐
- 【部署】Redis
- Source code analysis of ArrayList
- [UCOS III source code analysis] - mutually exclusive semaphores (mutually exclusive locks)
- 除了长安,这四个国产品牌也用“雷克萨斯脸”,中国设计倒退了?
- Developers share | handwriting operator is not so difficult. I'll teach you to use mindspire to realize adaptive average pooling operator!
- 毕业季--数据库常见面试题
- 开源十问, 社区新人快速上手指南
- Results of shooting competition Huawei od JS
- Omnivore, a non picky AI model, focuses on images, videos and 3D data!
- Win11预览版更新错误怎么办?Win11预览版安装失败的解决方法
猜你喜欢

Which kind of noise reduction Bluetooth headset is good? The most cost-effective active noise reduction Bluetooth headset

Open source ten questions, a quick start guide for community newcomers

技术干货| MindSpore新一代自主研发分子模拟库:Mind-Sponge
![[UCOS III source code analysis] - mutually exclusive semaphores (mutually exclusive locks)](/img/82/4f15e59c9e1679b24b350cebfa7935.png)
[UCOS III source code analysis] - mutually exclusive semaphores (mutually exclusive locks)

Uniapp Basics

LINGO求解分段函数最大(小)值

Leetcode 1342. Number of operations to change the number to 0

千亿元宇宙市场,Soul、映客的新动力

Network basic VLAN configuration (ENSP, Cisco)

Domestic light! High score spatiotemporal representation learning model uniformer
随机推荐
Ucos-iii learning notes - Software Timer
Omnivore, a non picky AI model, focuses on images, videos and 3D data!
Uniapp Basics
A New Optimizer Using Particle Swarm Theory
(manual) [sqli-labs58-61] limit the injection times: error injection, get injection, character / number type
Huawei od JS log sorting
UCOS III learning notes (11) -- task semaphores and task message queues
What about the update error of win11 preview? Solutions to the failure of win11 preview installation
Activity review | in depth chat with mindspire: how open source explores the whole scene of AI field
[UCOS III source code analysis] - Software Timer
语音转换主要涉及技术记录
Win11录屏怎么录声音?Win11录屏幕视频带声音的方法
Leetcode 1332. Delete the palindrome subsequence (after reading the problem solution, you suddenly realize
Nike, the leader of sports, is "red and black" in the trend of consumption recovery
Arduino窗口乱码问题
Definition and usage of several special standards of C language
Domestic light! High score spatiotemporal representation learning model uniformer
Quickly solve the problem of error or garbled code when inserting Chinese data into mysql
Voice conversion mainly involves technical records
【部署】Redis