Table of Contents
Mini program is an easy-to-use thing. For novices, if you read more official documents, you can initially make a relatively complete mini program. It is precisely because it is easy to get started and the functions are simple to implement, that mini programs are becoming more and more popular. The commercial value is also increasing. In this article, we will teach you a WeChat applet-imitation Hema Xiansheng.
Preliminary view of the project
First pass the onLoad life cycle function on the index interface,
The operations in the shopping cart are nothing more than additions and subtractions. You need to constantly debug by yourself to find out what is unreasonable
The CSS added in the global CSS style is adapted to all pages. From this, weui can be introduced, which is really convenient to make some interfaces
https: //github.com/fishman17/... Contains detailed comments
github: https://github.com/fishman17
Home WeChat Applet Mini Program Development WeChat Mini Program-Imitated Hema Fresh Food

WeChat Mini Program-Imitated Hema Fresh Food

Dec 05, 2017 pm 04:39 PM
Applets program

Mini program is an easy-to-use thing. For novices, if you read more official documents, you can initially make a relatively complete mini program. It is precisely because it is easy to get started and the functions are simple to implement, that mini programs are becoming more and more popular. The commercial value is also increasing. In this article, we will teach you a WeChat applet-imitation Hema Xiansheng.

Preliminary view of the project

Hema Fresh is Alibaba’s new retail format that has completely reconstructed offline supermarkets and is very popular.

WeChat Mini Program-Imitated Hema Fresh Food

WeChat Mini Program-Imitated Hema Fresh Food

WeChat Mini Program-Imitated Hema Fresh Food

WeChat Mini Program-Imitated Hema Fresh Food
WeChat Mini Program-Imitated Hema Fresh Food

#Project function

* 用户信息注册
* 首页几个轮播和界面交互
* 分类商品管理购买
* 购物车界面交互及其操作
* 个人信息界面
Copy after login
Copy after login

Mini program design process

Mini program is an easy thing to get started with. For novices, if you read more official documents, you can initially make a relatively complete mini program. Programs, precisely because they are easy to use and implement functions, are becoming more and more popular and have greater commercial value.

1. Project tools and documents

  1. WeChat web developer tools: WeChat Mini Program official website This is a relatively easy-to-use editor, which is very convenient for editing mini programs.

  2. Development Documents: WeChat Mini Program Secrets Use this to find APIs, components, frameworks, etc. of WeChat Mini Programs.

  3. Icon library: Iconfont-Alibaba vector icon library This can find almost all the small icons you want, which is very convenient.

  4. Easy Mork: easy-mock is used for background simulation to obtain JSON data;

  5. weui framework is introduced, such as personal information interface, using weui can be done quickly and conveniently

2. Project development

WeChat applet development is somewhat different from traditional H5 development, and it is easy to get into trouble.

The applet is a framework based on MVVM. It is very important to make reasonable use of data binding to update the interface.
When developing, don’t write and write all at once. Read more documents, and you will find that you accidentally write natively. a component. .

3. Project release

Enter the development platform, register project information->Upload the version in the editor->Select submit for review in the development version->Pass review-> Project online

Partial function analysis

Let’s take a look at my project directory first

    "pages": [
     "pages/index/index",  //主界面
      "pages/person/person", //个人界面
     "pages/classify/classify", //分类商品界面
     "pages/class/myFruits/myFruits", //水果商店
     "pages/class/myMeat/myMeat", //肉类食品商店
     "pages/myCart/myCart"    //购物车
     ],
Copy after login
Copy after login
1. Home page carousel image

There are several forms of carousel, For example, the common horizontal poster image display, as well as the horizontal and vertical product list display, and the headline information box rotation

siwper component very well realizes the horizontal poster image display, such as

        <swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}">
            <block wx:for="{{imgUrls}}" wx:key="index">
                <swiper-item>
                    <image src="{{item}}" class="slide-image"  />
                </swiper-item>
            </block>
        </swiper>
Copy after login
Copy after login
However, there are some differences that need to be paid attention to when sliding horizontally. Details

First add scroll-x-="true" to the swiper component
Then set display: inline-block; white-space: nowrap;
## to the parent container of the carousel's child elements #The headline information box conversion adopts up and down rotation, and is completed using scroll-view nested swiper

    <scroll-view scroll-y-="true"  >
                <swiper autoplay="{{autoplay}}" interval="{{interval1}}" duration="{{duration}}" vertical="true">
                    <block wx:for="{{something}}" wx:key="index">
                         //内容 
                    </block>
                </swiper>
    </scroll-view>
Copy after login
Copy after login

2. Classified product management

First pass the onLoad life cycle function on the index interface,

pass easy -moc obtains the background data and sends the necessary information to the global globalData

wx.request({
      url: 'http://www.easy-mock.com/mock/5a1ffb42583969285ab22bb7/orderOnline/orderOnline',
      complete: res => {
        this.globalData.classifyList = res.data;
      },
    })
Copy after login
Copy after login

For data processing, it is necessary to clarify which is global information and which is local informationFor example, all product information, shopping cart Products must be placed in the global view, and some, such as the status of the current interface, are generally stored in the Data of the current interface


. And some personal information, such as date of birth and account information, can be saved through wx. setStorage and wx.getStorage are put into local storage

3. Shopping cart operation

The operations in the shopping cart are nothing more than additions and subtractions. You need to constantly debug by yourself to find out what is unreasonable

Through operations such as view and bindtap in buttons, the modification of product information and the processing of shopping cart status can be achieved.


For example, reduce the number of items in the shopping cart.

reduceItems: function (e) {
    let carts = app.globalData.carts;    //获取购物车的信息
    let classifyList = app.globalData.classifyList;  //获取商品的信息
    for (let key of carts) {                        //遍历购物车数组
      if (key.id === e.target.dataset.id) {         //通过WXML中 view里面的bind-id传过来的参数进行查找
        key.cartSelected = true;
        if (key.num === 1) {                  //如果数量为1还要减
          key.num--;
          key.cartSelected = false;           //购物车不选中
          key.selected = false;               //商品中不选中
          app.globalData.carts = carts.filter((item) => {    //进行购物车中商品剔除
            return item.id != e.target.dataset.id;
          })
        } else {
          key.num--;
        }
      }
    }
    let num = 0;                                 //实时更新购物车小计界面显示
    let totalPrice = 0;
    for (let key of carts) {
      if (key.cartSelected) {
        num += key.num;
        totalPrice += key.num * key.price;
      }
    }
    this.setData({                          //通过setData进行当前页面Data数据管理
      cart: app.globalData.carts,
      cartTotal: num,
      cartTotalPrice: totalPrice,
    })
  },
Copy after login
Copy after login

4 .weui framework introduces

The CSS added in the global CSS style is adapted to all pages. From this, weui can be introduced, which is really convenient to make some interfaces

@import './styles/weui.wxss';
Copy after login
Copy after login

Summary

    The components of the WeChat mini program, the API is very powerful, it requires continuous exploration, continuous learning, and reading more documents
  1. Be good at using effective resources, such as iconfont esay -moc weui etc.
  2. Be careful when cutting pages, and be good at using flexible layout and other layout methods. The rpx of the mini program is really easy to use
  3. Don’t Write code in one go. When functions are reusable, they should be abstracted and encapsulated so that the code is easy to maintain and read.
  4. Project address:

https: //github.com/fishman17/... Contains detailed comments

Personal profile

github: https://github.com/fishman17

Email: 734583898@qq.com


Finally, if you like this project, please give it a star. Thank you!


Preliminary view of the project

Imitate Hema Xiansheng and realize some functions.


Hema Fresh is a new retail format that Alibaba has completely reconstructed for offline supermarkets. It is very popular

WeChat Mini Program-Imitated Hema Fresh Food

WeChat Mini Program-Imitated Hema Fresh Food

WeChat Mini Program-Imitated Hema Fresh Food

WeChat Mini Program-Imitated Hema Fresh Food
WeChat Mini Program-Imitated Hema Fresh Food

##Project function

* 用户信息注册
* 首页几个轮播和界面交互
* 分类商品管理购买
* 购物车界面交互及其操作
* 个人信息界面
Copy after login
Copy after login

Mini program design process

Mini program is an easy thing to get started with, for novices Generally speaking, if you read more official documents, you can initially make a relatively complete mini program. Precisely because it is easy to get started and the functions are simple to implement, mini programs are becoming more and more popular and their commercial value is also increasing.

1. Project tools and documents

  1. WeChat web developer tools: WeChat Mini Program official website This is a relatively easy-to-use editor, which is very convenient for editing mini programs.

  2. Development Documents: WeChat Mini Program Secrets Use this to find APIs, components, frameworks, etc. of WeChat Mini Programs.

  3. Icon library: Iconfont-Alibaba vector icon library This can find almost all the small icons you want, which is very convenient.

  4. Easy Mork: easy-mock is used for background simulation to obtain JSON data;

  5. weui framework is introduced, such as personal information interface, using weui can be done quickly and conveniently

2. Project development

WeChat applet development is somewhat different from traditional H5 development, and it is easy to get into trouble.

The applet is a framework based on MVVM. It is very important to make reasonable use of data binding to update the interface.
When developing, don’t write and write all at once. Read more documents, and you will find that you accidentally write natively. a component. .

3. Project release

Enter the development platform, register project information->Upload the version in the editor->Select submit for review in the development version->Pass review-> Project online

Partial function analysis

Let’s take a look at my project directory first

    "pages": [
     "pages/index/index",  //主界面
      "pages/person/person", //个人界面
     "pages/classify/classify", //分类商品界面
     "pages/class/myFruits/myFruits", //水果商店
     "pages/class/myMeat/myMeat", //肉类食品商店
     "pages/myCart/myCart"    //购物车
     ],
Copy after login
Copy after login
1. Home page carousel image

There are several forms of carousel, For example, the common horizontal poster image display, as well as the horizontal and vertical product list display, and the headline information box rotation

siwper component very well realizes the horizontal poster image display, such as

        <swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}">
            <block wx:for="{{imgUrls}}" wx:key="index">
                <swiper-item>
                    <image src="{{item}}" class="slide-image"  />
                </swiper-item>
            </block>
        </swiper>
Copy after login
Copy after login
However, there are some differences that need to be paid attention to when sliding horizontally. Details

First add scroll-x-="true" to the swiper component
Then set display: inline-block; white-space: nowrap;
## to the parent container of the carousel's child elements #The headline information box conversion adopts up and down rotation, and is completed using scroll-view nested swiper

    <scroll-view scroll-y-="true"  >
                <swiper autoplay="{{autoplay}}" interval="{{interval1}}" duration="{{duration}}" vertical="true">
                    <block wx:for="{{something}}" wx:key="index">
                         //内容 
                    </block>
                </swiper>
    </scroll-view>
Copy after login
Copy after login

2. Classified product management

First pass the onLoad life cycle function on the index interface,

pass easy -moc obtains the background data and sends the necessary information to the global globalData

wx.request({
      url: 'http://www.easy-mock.com/mock/5a1ffb42583969285ab22bb7/orderOnline/orderOnline',
      complete: res => {
        this.globalData.classifyList = res.data;
      },
    })
Copy after login
Copy after login

For data processing, it is necessary to clarify which is global information and which is local informationFor example, all product information, shopping cart Products must be placed in the global view, and some, such as the status of the current interface, are generally stored in the Data of the current interface


. And some personal information, such as date of birth and account information, can be saved through wx. setStorage and wx.getStorage are put into local storage

3. Shopping cart operation

The operations in the shopping cart are nothing more than additions and subtractions. You need to constantly debug by yourself to find out what is unreasonable

Through operations such as view and bindtap in buttons, the modification of product information and the processing of shopping cart status can be achieved.


For example, reduce the number of items in the shopping cart.

reduceItems: function (e) {
    let carts = app.globalData.carts;    //获取购物车的信息
    let classifyList = app.globalData.classifyList;  //获取商品的信息
    for (let key of carts) {                        //遍历购物车数组
      if (key.id === e.target.dataset.id) {         //通过WXML中 view里面的bind-id传过来的参数进行查找
        key.cartSelected = true;
        if (key.num === 1) {                  //如果数量为1还要减
          key.num--;
          key.cartSelected = false;           //购物车不选中
          key.selected = false;               //商品中不选中
          app.globalData.carts = carts.filter((item) => {    //进行购物车中商品剔除
            return item.id != e.target.dataset.id;
          })
        } else {
          key.num--;
        }
      }
    }
    let num = 0;                                 //实时更新购物车小计界面显示
    let totalPrice = 0;
    for (let key of carts) {
      if (key.cartSelected) {
        num += key.num;
        totalPrice += key.num * key.price;
      }
    }
    this.setData({                          //通过setData进行当前页面Data数据管理
      cart: app.globalData.carts,
      cartTotal: num,
      cartTotalPrice: totalPrice,
    })
  },
Copy after login
Copy after login

4 .weui framework introduces

The CSS added in the global CSS style is adapted to all pages. From this, weui can be introduced, which is really convenient to make some interfaces

@import './styles/weui.wxss';
Copy after login
Copy after login

Summary

    The components of the WeChat mini program, the API is very powerful, it requires continuous exploration, continuous learning, and reading more documents
  1. Be good at using effective resources, such as iconfont esay -moc weui etc.
  2. Be careful when cutting pages, and be good at using flexible layout and other layout methods. The rpx of the mini program is really easy to use
  3. Don’t Write code in one go. When functions are reusable, they should be abstracted and encapsulated so that the code is easy to maintain and read.
  4. The above content is the Hema Fresh WeChat applet. I hope it can help everyone.

Related recommendations:

Introduction examples of WeChat mini program development

Detailed explanation of WeChat mini program video, music, and picture components

A case study on how WeChat applet can obtain WeChat exercise steps (picture)

The above is the detailed content of WeChat Mini Program-Imitated Hema Fresh Food. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to make Google Maps the default map in iPhone How to make Google Maps the default map in iPhone Apr 17, 2024 pm 07:34 PM

The default map on the iPhone is Maps, Apple's proprietary geolocation provider. Although the map is getting better, it doesn't work well outside the United States. It has nothing to offer compared to Google Maps. In this article, we discuss the feasible steps to use Google Maps to become the default map on your iPhone. How to Make Google Maps the Default Map in iPhone Setting Google Maps as the default map app on your phone is easier than you think. Follow the steps below – Prerequisite steps – You must have Gmail installed on your phone. Step 1 – Open the AppStore. Step 2 – Search for “Gmail”. Step 3 – Click next to Gmail app

How to write a simple countdown program in C++? How to write a simple countdown program in C++? Nov 03, 2023 pm 01:39 PM

C++ is a widely used programming language that is very convenient and practical in writing countdown programs. Countdown program is a common application that can provide us with very precise time calculation and countdown functions. This article will introduce how to use C++ to write a simple countdown program. The key to implementing a countdown program is to use a timer to calculate the passage of time. In C++, we can use the functions in the time.h header file to implement the timer function. The following is the code for a simple countdown program

Clock app missing in iPhone: How to fix it Clock app missing in iPhone: How to fix it May 03, 2024 pm 09:19 PM

Is the clock app missing from your phone? The date and time will still appear on your iPhone's status bar. However, without the Clock app, you won’t be able to use world clock, stopwatch, alarm clock, and many other features. Therefore, fixing missing clock app should be at the top of your to-do list. These solutions can help you resolve this issue. Fix 1 – Place the Clock App If you mistakenly removed the Clock app from your home screen, you can put the Clock app back in its place. Step 1 – Unlock your iPhone and start swiping to the left until you reach the App Library page. Step 2 – Next, search for “clock” in the search box. Step 3 – When you see “Clock” below in the search results, press and hold it and

How to open a website using Task Scheduler How to open a website using Task Scheduler Oct 02, 2023 pm 11:13 PM

Do you frequently visit the same website at about the same time every day? This can lead to spending a lot of time with multiple browser tabs open and cluttering the browser while performing daily tasks. Well, how about opening it without having to launch the browser manually? It's very simple and doesn't require you to download any third-party apps, as shown below. How do I set up Task Scheduler to open a website? Press the key, type Task Scheduler in the search box, and then click Open. Windows On the right sidebar, click on the Create Basic Task option. In the Name field, enter the name of the website you want to open and click Next. Next, under Triggers, click Time Frequency and click Next. Select how long you want the event to repeat and click Next. Select enable

Can't allow access to camera and microphone in iPhone Can't allow access to camera and microphone in iPhone Apr 23, 2024 am 11:13 AM

Are you getting "Unable to allow access to camera and microphone" when trying to use the app? Typically, you grant camera and microphone permissions to specific people on a need-to-provide basis. However, if you deny permission, the camera and microphone will not work and will display this error message instead. Solving this problem is very basic and you can do it in a minute or two. Fix 1 – Provide Camera, Microphone Permissions You can provide the necessary camera and microphone permissions directly in settings. Step 1 – Go to the Settings tab. Step 2 – Open the Privacy & Security panel. Step 3 – Turn on the “Camera” permission there. Step 4 – Inside, you will find a list of apps that have requested permission for your phone’s camera. Step 5 – Open the “Camera” of the specified app

iOS 17: How to organize iMessage apps in Messages iOS 17: How to organize iMessage apps in Messages Sep 18, 2023 pm 05:25 PM

In iOS 17, Apple not only added several new messaging features, but also tweaked the design of the Messages app to give it a cleaner look. All iMessage apps and tools, such as the camera and photo options, can now be accessed by tapping the "+" button above the keyboard and to the left of the text input field. Clicking the "+" button brings up a menu column with a default order of options. Starting from the top, there's camera, photos, stickers, cash (if available), audio, and location. At the very bottom is a "More" button, which when tapped will reveal any other installed messaging apps (you can also swipe up to reveal this hidden list). How to reorganize your iMessage app You can do this below

Identity matrix program in C language Identity matrix program in C language Aug 30, 2023 am 10:45 AM

Given a square matrix M[r][c], where "r" is a certain number of rows and "c" are columns such that r=c, we have to check if "M" is the identity matrix. Identity matrix Identity matrix is ​​also known as identity matrix of size nxn square matrix in which the integer value of diagonal elements is 1 and the integer value of non-diagonal elements is 0 like the example given below-$$I1=\ begin{bmatrix}1\end{bmatrix},\I2=\begin{bmatrix}1&0\0&1\end{bmatrix},\I3=\begin{bmatrix}1&0&0\0&1&0\0&amp

How to download and install Samsung NVME drivers on Windows 11 How to download and install Samsung NVME drivers on Windows 11 Aug 23, 2023 pm 06:01 PM

We reiterate the importance of regularly updating your drivers. A good driver can make a huge difference on your PC, and NVMe drivers are no exception. In today's article, our main focus is on Samsung NVMe drivers. We'll look at how to download and install it on Windows 11, potential problems that can arise from installing the wrong driver, and how to optimize it. Do Samsung NVMe drivers work with Windows 11? Yes, Samsung NVMe drivers are available for Windows 11, provided you meet all system requirements. Samsung NVMe driver software allows your Windows operating system to recognize and communicate with your Samsung NVMe SSD. If you don't have this driver

See all articles