Home WeChat Applet Mini Program Development Summary of problems encountered in WeChat applet development

Summary of problems encountered in WeChat applet development

Jan 25, 2018 pm 03:08 PM
Applets Summary Program development

The development of the WeChat mini program has been completed, and naturally we have encountered many problems. In this article, we mainly share with you a summary of the problems encountered in the development of the WeChat mini program, hoping to help more WeChat developers.

Introduction to the mini program

"Let your interests no longer be lonely, let your hobbies no longer wander" is the theme of the WeChat mini program "Let's Go Together". This mini program aims to solve The loneliness of contemporary college students in campus life allows everyone to find like-minded friends and partners in activities such as running, fitness, and competitions. By combining the instant-use and easy-to-use features of the mini program with making friends, it will be an efficient, fast, and burden-free offline dating tool

This mini program is provided by bmob back-end cloud Data processing and storage support

Small program code

Summary of problems encountered in WeChat applet development

Summary of technical issues in development

1. The emergence of using e.target.dataset Question

In the process of developing small programs, we often use the attribute values ​​​​of attributes in tags. We usually set data-*="{{XXX}}" in and then in JS I use e.target.dateset.* to get the XXX value, but I often encounter undefined. Use console.log(e) to check the output information and you will find that the e object contains two objects, namely currentTarget and target. , and sometimes the data is in currentTarget,

At this time, you can replace the code with this to get the value

WXML

<view bindtap="bintap" data-id="1"></view>
Copy after login

JS

bintap:function(e){
    var id = e.currentTarget.dataset.id;
}
Copy after login

Online There is also a saying that the naming problem of * in data-* can be solved by removing the camel case naming and using pure lower case

2. How to display the real-time word count in the textarea text box of the applet

WXML

<view> <view> <textarea name="content" bindinput="bindTextAreaChange" 
maxlength="{{noteMaxLen}}" /> <view class="chnumber">
{{noteNowLen}}/{{noteMaxLen}}</view> </view> </view>
Copy after login

JS

data:{
    noteMaxLen: 200,//备注最多字数
    noteNowLen: 0,//备注当前字数
}
  //字数改变触发事件
  bindTextAreaChange: function (e) {
    var that = this var value = e.detail.value,
      len = parseInt(value.length);
    if (len > that.data.noteMaxLen)
      return;
    that.setData({
      content: value, noteNowLen: len
    })
  },
Copy after login

3. Use JS to implement fuzzy query

Since we are using the data processing and storage support provided by Bmob back-end cloud, according to the development documents provided by Bmob, The free version of the application cannot perform fuzzy queries. Seeing this, and then looking at the almost completed activity search interface, I feel indescribable. Just when I was about to give up, I suddenly thought of a method, which is to first save all the background data into a collection, and then match it one by one according to the entered search value. After thinking about it, I started to work immediately. I checked the javaScript first. Document, String object has a method called indexOf(), which can return the position where a specified string value first appears in the string. In this way, it traverses all the data and retrieves each character of each piece of data. If it appears If so, add it to the collection of search results.

JS

//js 实现模糊匹配查询
  findEach: function (e) {
    var that = this var strFind = that.data.wxSearchData.value; //这里使用的 wxSearch 搜索UI插件, if (strFind == null || strFind == "") {
      wx.showToast({
        title: &#39;输入为空&#39;,
        icon: &#39;loading&#39;,
      })
    }
    if (strFind != "") {
      var nPos;
      var resultPost = [];
      for (var i in smoodList) {
        var sTxt = smoodList[i].title || &#39;&#39;; //活动的标题
        nPos = sTxt.indexOf(strFind); 
        if (nPos >= 0) {//如果输入的关键字在该活动标题中出现过,则匹配该活动
          resultPost.push(smoodList[i]); //将该活动加入到搜索到的活动列表中
        }
      }
      that.setData({
        moodList: resultPost
      })
    }
  },
Copy after login

For more detailed code, please go to Github to view

4. Use JS to format the time in the string Convert to seconds ago, minutes ago...

Since the mini program involves a series of functions including commenting, joining activities, collections, etc. including event time, the time format stored in the database is 2017-11- 30 23:36:10 Now I want to not display the specific time on the interface, but to display the difference from the current time, that is, a few seconds ago, a few minutes ago, etc.

It is not complicated to implement, the main idea It is to first convert the time of the string into a timestamp, and then compare it with the current timestamp, so that it can be converted into a few seconds ago, a few minutes ago, a few hours ago, a few days ago, etc.

JavaScript Interaction is not like html + jS. Use dataSet({}) to assign values. The view layer can activate the values ​​​​in an asynchronous manner. So I thought that after submitting the form, assign the values ​​​​to these inputs to be empty, and that will be achieved. In order to clear the form, of course, the form does not only contain input, but the clearing effect can be achieved in this way

WXML

//字符串转换为时间戳 function getDateTimeStamp(dateStr) {
  return Date.parse(dateStr.replace(/-/gi, "/"));
}
//格式化时间 function getDateDiff(dateStr) {
  var publishTime = getDateTimeStamp(dateStr) / 1000,
    d_seconds,
    d_minutes,
    d_hours,
    d_days,
    timeNow = parseInt(new Date().getTime() / 1000),
    d,
    date = new Date(publishTime * 1000),
    Y = date.getFullYear(),
    M = date.getMonth() + 1,
    D = date.getDate(),
    H = date.getHours(),
    m = date.getMinutes(),
    s = date.getSeconds();
  //小于10的在前面补0 if (M < 10) {
    M = &#39;0&#39; + M;
  }
  if (D < 10) {
    D = &#39;0&#39; + D;
  }
  if (H < 10) {
    H = &#39;0&#39; + H;
  }
  if (m < 10) {
    m = &#39;0&#39; + m;
  }
  if (s < 10) {
    s = &#39;0&#39; + s;
  }
  d = timeNow - publishTime;
  d_days = parseInt(d / 86400);
  d_hours = parseInt(d / 3600);
  d_minutes = parseInt(d / 60);
  d_seconds = parseInt(d);
  if (d_days > 0 && d_days < 3) {
    return d_days + &#39;天前&#39;;
  } else if (d_days <= 0 && d_hours > 0) {
    return d_hours + &#39;小时前&#39;;
  } else if (d_hours <= 0 && d_minutes > 0) {
    return d_minutes + &#39;分钟前&#39;;
  } else if (d_seconds < 60) {
    if (d_seconds <= 0) {
      return &#39;刚刚&#39;;
    } else {
      return d_seconds + &#39;秒前&#39;;
    }
  } else if (d_days >= 3 && d_days < 30) {
    return M + &#39;-&#39; + D + &#39; &#39; + H + &#39;:&#39; + m;
  } else if (d_days >= 30) {
    return Y + &#39;-&#39; + M + &#39;-&#39; + D + &#39; &#39; + H + &#39;:&#39; + m;
  }
}
Copy after login

JS

<form bindsubmit="submitForm"> <text class="key">活动名称</text>
 <input name="title" maxlength="100" value="{{title}}" /> 
 <button formType="submit">确定</button> </form>
Copy after login

6. Micro Signal, QQ number, mobile phone number regular verification

Since applying to join the event requires filling in real name, contact information and other information, in order to prevent users from filling in information at will, this information must be verified

JS

submitForm:function(e){
     var title = e.detail.value.title;
     ......
     success: function (res) {
         //将title值设置空
        that.setData({
            title: &#39;&#39;
         }
     }
}
Copy after login

7. Use Bmob SDK to realize successful registration, send template messages, generate mini program QR codes, etc.

During the development process, because of what you want to achieve, what happens when the user successfully registers? Notify the user, after checking the development documentation of the mini program, I found that there is an API for sending template messages. Then I checked the development documentation of Bmob and found that this function has been implemented. This is really useful. Template messages can only be sent successfully on a real machine. After configuration, the key is successful, but there is a problem during use

, that is, after the mini program is released, if the template message contains the page parameter, it will not be sent, but it can be sent successfully in the development version. This problem has been reported Yes, it is estimated that this problem will be solved after the Bmob mini program SDK is updated.

Related recommendations:


A WeChat mini program version of Zhihu example sharing

Solutions and methods of componentizing WeChat mini programs

WeChat Mini Program Version 2048 Mini Game

The above is the detailed content of Summary of problems encountered in WeChat applet development. 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
3 weeks 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)

Develop WeChat applet using Python Develop WeChat applet using Python Jun 17, 2023 pm 06:34 PM

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

Can small programs use react? Can small programs use react? Dec 29, 2022 am 11:06 AM

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.

Implement card flipping effects in WeChat mini programs Implement card flipping effects in WeChat mini programs Nov 21, 2023 am 10:55 AM

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: &lt;!--index.wxml--&gt;&l

Alipay launched the 'Chinese Character Picking-Rare Characters' mini program to collect and supplement the rare character library Alipay launched the 'Chinese Character Picking-Rare Characters' mini program to collect and supplement the rare character library Oct 31, 2023 pm 09:25 PM

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 achieves rapid conversion between mini programs and H5 How uniapp achieves rapid conversion between mini programs and H5 Oct 20, 2023 pm 02:12 PM

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

How to operate mini program registration How to operate mini program registration Sep 13, 2023 pm 04:36 PM

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.

Tutorial on writing a simple chat program in Python Tutorial on writing a simple chat program in Python May 08, 2023 pm 06:37 PM

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

Introduction to WeChat applet development in Java language Introduction to WeChat applet development in Java language Jun 09, 2023 pm 10:40 PM

WeChat applet is a lightweight application that can be run on the WeChat platform. It does not require downloading and installation, which is convenient and fast. Java language, as a language widely used in enterprise-level application development, can also be used for the development of WeChat applets. In Java language, you can use the SpringBoot framework and third-party toolkits to develop WeChat applets. The following is a simple WeChat applet development process. To create a WeChat mini program, first, you need to register a mini program on the WeChat public platform. After successful registration, you can obtain

See all articles