search
HomeWeChat AppletMini Program DevelopmentIntroduction to the encapsulation of the WeChat applet request interface

This article mainly introduces the relevant information about the encapsulation example code of the WeChat applet request interface. Friends who need it can refer to

The encapsulation example code of the WeChat applet request interface

Encapsulation of the mini program request interface (essentially calling back the request callback function again)

module.exports.getData = function (url) {
 var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
 var method = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'POST';
 var header = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' };

 return new Promise(function (resolve, reject) {
 wx.request({
  url: url,
  data: data,
  method: method,
  header: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
  success: function (res) {
  resolve(res)
  },
  fail: function (res) {
  reject(res)
  }
 })
 })
}

Calling method

var common = require("../../common/common.js")
common.getData(postUrl)
 .then(function(data){
  this.setData({
  //....
  });
  console.log(data);
 });

The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Introduction to the WeChat Mini Program network request wx.request

Video API in the WeChat Mini Program Parse

The above is the detailed content of Introduction to the encapsulation of the WeChat applet request interface. For more information, please follow other related articles on the PHP Chinese website!

Statement
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)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools