Write this article is for their own later development of small program projects to facilitate CV



I. Interface development processIi. Domain name configuration of wechat public platform

Note: HTTPS must be configured, the domain name configured on the applets must be registered domain name, and the server must be TLS1.2 or higher



Open the wechat developer tool, open your project, click the details. Make sure the domain names are one-by-one



Create api.js http.js in your project utils file



Http.js code (just copy it)

HTTP (url, method, params) {let token = 'token' // Let sign = 'sign' // get the signature. Let data = {token, sign} if (params.data) {// If (params.data) {let data = {token, sign} if (params.data) {// If (params.data) { Indicates the data requested to be sent, success: successful callback, fail: For (let key in params.data) {// select null for (let key in params.data); Delete this property if (params. Data [key] = = null | | params. Data [key] = = 'null') {delete params. Data [key]}} data = {... data, ... Params. Data}} wx.request({url: 'you configured the domain name' + url, // is open to the method: method == 'post'? Data, header: {'content-type': {'content-type': {'content-type': {'content-type': 'application/json' }, success(res) { params.success && params.success(res.data) }, fail(err) { params.fail && params.fail(err) } }) } }Copy the code

Api.js (just copy the code again)

import { http } from './http'; // Import the syntax of ES6, Function femaleNameApi(params) {// Request interface HTTP ('project/projectInfos', 'get', } // Each interface defines a function, and then exposes it, Function novelApi(params) {HTTP ('/novelApi', 'get', params)} export default {// femaleNameApi, novelApi }Copy the code

Call (you can use it wherever you want)

Page({onLoad: function (){this.getData()}, getData(){http.femalenameAPI ({// call data: {token: '470712 ff0fe2392d6cb6d8a6560805cc'}, success: res = > {the console. The log (' interface request is successful, the res) enclosing setData ({femaleList: res.data }) }, fail: err => { console.log(err) } }) } })Copy the code

This article reference in www.cnblogs.com/ifannie/p/1…