Share a small program development experience
This is the first time I have officially developed a small program. Let me talk about the development process and experience of the small program from the following aspects, mainly talking about the functions used in this project.
Data Request
This mini program does not have many additional functions, so the data and data processing are this time The main work is that the mini program provides APIs to users for users to request data from their own servers. It is worth mentioning that before developing the mini program, you need to apply for an appID on the WeChat public platform and bind a domain name. The domain name must be https protocol. Then complete the information in the configuration information of the mini program development tool. The requested address needs to be under the previously bound domain name. In this project, wx.request is used to pull data from the server.
wx.request({ url: that.data.couponData.requestUrl, data: that.data.couponData.queryData, header: { 'content-type': 'application/json' }, success: function(res) { var list = res.data.goodsList; console.log(res.data); for(var i in list) { list[i].quanUsedNum = parseInt(list[i].quanTotalNum) - parseInt(list[i].quanRemainNum); list[i].isImgRendered = false; } list[0].isImgRendered = list[1].isImgRendered = list[2].isImgRendered = list[3].isImgRendered = true; that.setData({"couponData.totalPage":res.data.totalPage}); that.setData({"couponData.list":that.data.couponData.list.concat(list)}); that.setData({"couponData.loadmore":!that.data.couponData.loadmore}); that.setData({"couponData.queryData.pageNum":parseInt(that.data.couponData.queryData.pageNum) + 1}); if(that.data.couponData.queryData.pageNum > that.data.couponData.totalPage) { that.setData({"couponData.isAction":false}); } if(that.data.couponData.list.length < 1) { that.setData({"couponData.nodata":true}); } if(f) { f(); } } });
Data cache
The data cache is used here because a search function is required, which involves data transfer between pages. It is also a method in the address. You can also borrow localStorage. Use wx.setStorage to store the data in localStorage. After the page jumps, just read from localStorage. When reading the data, it is divided into synchronous reading and Read asynchronously.
Clipboard application
You can easily copy any information to the clipboard by borrowing the API of the applet, and then paste it.
wx.setClipboardData({ data: '【' + that.data.couponData.list[e.currentTarget.id].goodsTitle + '】复制这条信息,打开【手机淘宝】' + that.data.couponData.list[e.currentTarget.id].twoInOneKouling, success: function(res) { that.setData({"couponData.copyTip":true,"couponData.Kouling":that.data.couponData.list[e.currentTarget.id].twoInOneKouling}) } });
Copy after loginTemplate
In this project, the pages are basically similar, but there are subtle differences, so a template is used, and a new template/template.wxml is created. The name attribute must be set up.<template name='navsearch'> <view class='nav-search'> <view class='nav-search__container space-between'> <view class='nav-search__search' wx:if='{{isSearch}}'></view> <input class='nav-search__input' placeholder='请输入关键词找券' name='queryStr' value="{{queryStr}}" bindfocus='toggleSearch' bindconfirm='doQuery' bindinput="syncQuery"/> <view class='nav-search__delete' wx:if='{{!isSearch}}' bindtap='deleteAll'></view> <view class='nav-search__btn center' wx:if='{{!isSearch}}' bindtap='doQuery'>搜索</view> </view> <view class='nav-filter' bindtap='toggleFilter'></view> </view> </template> <!--在其他文件中使用模板--> <import src="/template/template.wxml" /> <template is='navsearch' data="{{...couponData}}"></template>
Copy after loginModularization
For public js, you can write it in a special js file, and then use module.exports to expose the interface.
Common js files are introduced using require.var common = require('../../common/common.js'); ... common.f(); //调用
Copy after loginredirectTo & navigateTo
redirectTo redirects to a certain page, and navigateTo opens a new page. It is worth mentioning that there are too many pages opened using navigateTo. It will cause the mini program to freeze.
Share
Page({ onShareAppMessage: function () { return { title: 'your title!', path: '/xxxx/xxxx/xxxx', //分享之后回到这个页面 success: function(res) { f(); //成功回调; }, fail: function(res) { f(); //失败回调; } } } })
Copy after loginImprove the smoothness of list sliding
In short, where the page scrolls, in the list Where the picture is displayed, the implementation method is as follows.
//js文件 Page({ loadImg:function(e) { //计算接下来加载哪几张 var index = Math.floor((e.detail.scrollTop - 8)/259.5); var temp = this.data.couponData.list; //完整的列表 var min = Math.max(index * 2,0),max = Math.min(index * 2 + 8,temp.length); for(var i = min; i < max; i ++) { if(temp[i] && !temp[i].isImgRendered) { temp[i].isImgRendered = true; //列表中的每一项有一个标记是否加载图片的的属性,默认false,随着页面滚动,一个个变成true。 } } this.setData({"couponData.list":temp}); temp = null; }, }) //wxml文件中在scroll-view上绑定事件。 <scroll-view class="section" scroll-y="true" bindscroll='loadImg'></scroll-view>
Copy after loginThe above is the detailed content of Share a small program development experience. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



With the popularity of mobile Internet technology and smartphones, WeChat has become an indispensable application in people's lives. WeChat mini programs allow people to directly use mini programs to solve some simple needs without downloading and installing applications. This article will introduce how to use Python to develop WeChat applet. 1. Preparation Before using Python to develop WeChat applet, you need to install the relevant Python library. It is recommended to use the two libraries wxpy and itchat here. wxpy is a WeChat machine

Mini programs can use react. How to use it: 1. Implement a renderer based on "react-reconciler" and generate a DSL; 2. Create a mini program component to parse and render DSL; 3. Install npm and execute the developer Build npm in the tool; 4. Introduce the package into your own page, and then use the API to complete the development.

Implementing card flipping effects in WeChat mini programs In WeChat mini programs, implementing card flipping effects is a common animation effect that can improve user experience and the attractiveness of interface interactions. The following will introduce in detail how to implement the special effect of card flipping in the WeChat applet and provide relevant code examples. First, you need to define two card elements in the page layout file of the mini program, one for displaying the front content and one for displaying the back content. The specific sample code is as follows: <!--index.wxml-->&l

According to news from this site on October 31, on May 27 this year, Ant Group announced the launch of the "Chinese Character Picking Project", and recently ushered in new progress: Alipay launched the "Chinese Character Picking-Uncommon Characters" mini program to collect collections from the society Rare characters supplement the rare character library and provide different input experiences for rare characters to help improve the rare character input method in Alipay. Currently, users can enter the "Uncommon Characters" applet by searching for keywords such as "Chinese character pick-up" and "rare characters". In the mini program, users can submit pictures of rare characters that have not been recognized and entered by the system. After confirmation, Alipay engineers will make additional entries into the font library. This website noticed that users can also experience the latest word-splitting input method in the mini program. This input method is designed for rare words with unclear pronunciation. User dismantling

How uniapp can achieve rapid conversion between mini programs and H5 requires specific code examples. In recent years, with the development of the mobile Internet and the popularity of smartphones, mini programs and H5 have become indispensable application forms. As a cross-platform development framework, uniapp can quickly realize the conversion between small programs and H5 based on a set of codes, greatly improving development efficiency. This article will introduce how uniapp can achieve rapid conversion between mini programs and H5, and give specific code examples. 1. Introduction to uniapp unia

Implementation idea: Establishing the server side of thread, so as to process the various functions of the chat room. The establishment of the x02 client is much simpler than the server. The function of the client is only to send and receive messages, and to enter specific characters according to specific rules. To achieve the use of different functions, therefore, on the client side, you only need to use two threads, one is dedicated to receiving messages, and the other is dedicated to sending messages. As for why not use one, that is because, only

Mini program registration operation steps: 1. Prepare copies of personal ID cards, corporate business licenses, legal person ID cards and other filing materials; 2. Log in to the mini program management background; 3. Enter the mini program settings page; 4. Select " "Basic Settings"; 5. Fill in the filing information; 6. Upload the filing materials; 7. Submit the filing application; 8. Wait for the review results. If the filing is not passed, make modifications based on the reasons and resubmit the filing application; 9. The follow-up operations for the filing are Can.

1. Open the WeChat mini program and enter the corresponding mini program page. 2. Find the member-related entrance on the mini program page. Usually the member entrance is in the bottom navigation bar or personal center. 3. Click the membership portal to enter the membership application page. 4. On the membership application page, fill in relevant information, such as mobile phone number, name, etc. After completing the information, submit the application. 5. The mini program will review the membership application. After passing the review, the user can become a member of the WeChat mini program. 6. As a member, users will enjoy more membership rights, such as points, coupons, member-exclusive activities, etc.
