微信小程序 请求函数 同步封装方法

距上回说到,我们使用微信小程序请求函数时,需要多次调用,之前我们封装了一套代码,但是他是异步的,当我们下一个请求函数需要的数据是上一个请求函数得到的时候,就不可以了,所以我就又封装了一个同步的请求函数的方法.
我们首先需要引入es6的js

/*!* @overview es6-promise - a tiny implementation of Promises/A+.* @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)* @license   Licensed under MIT license*            See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE* @version   v4.2.4+314e4831*/(function (global, factory) {typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :typeof define === 'function' && define.amd ? define(factory) :(global.ES6Promise = factory());
}(this, (function () {'use strict';function objectOrFunction(x) {var type = typeof x;return x !== null && (type === 'object' || type === 'function');}function isFunction(x) {return typeof x === 'function';}var _isArray = void 0;if (Array.isArray) {_isArray = Array.isArray;} else {_isArray = function (x) {return Object.prototype.toString.call(x) === '[object Array]';};}var isArray = _isArray;var len = 0;var vertxNext = void 0;var customSchedulerFn = void 0;var asap = function asap(callback, arg) {queue[len] = callback;queue[len + 1] = arg;len += 2;if (len === 2) {// If len is 2, that means that we need to schedule an async flush.// If additional callbacks are queued before the queue is flushed, they// will be processed by this flush that we are scheduling.if (customSchedulerFn) {customSchedulerFn(flush);} else {scheduleFlush();}}};function setScheduler(scheduleFn) {customSchedulerFn = scheduleFn;}function setAsap(asapFn) {asap = asapFn;}var browserWindow = typeof window !== 'undefined' ? window : undefined;var browserGlobal = browserWindow || {};var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && {}.toString.call(process) === '[object process]';// test for web worker but not in IE10var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined';// nodefunction useNextTick() {// node version 0.10.x displays a deprecation warning when nextTick is used recursively// see https://github.com/cujojs/when/issues/410 for detailsreturn function () {return process.nextTick(flush);};}// vertxfunction useVertxTimer() {if (typeof vertxNext !== 'undefined') {return function () {vertxNext(flush);};}return useSetTimeout();}function useMutationObserver() {var iterations = 0;var observer = new BrowserMutationObserver(flush);var node = document.createTextNode('');observer.observe(node, {characterData: true});return function () {node.data = iterations = ++iterations % 2;};}// web workerfunction useMessageChannel() {var channel = new MessageChannel();channel.port1.onmessage = flush;return function () {return channel.port2.postMessage(0);};}function useSetTimeout() {// Store setTimeout reference so es6-promise will be unaffected by// other code modifying setTimeout (like sinon.useFakeTimers())var globalSetTimeout = setTimeout;return function () {return globalSetTimeout(flush, 1);};}var queue = new Array(1000);function flush() {for (var i = 0; i < len; i += 2) {var callback = queue[i];var arg = queue[i + 1];callback(arg);queue[i] = undefined;queue[i + 1] = undefined;}len = 0;}function attemptVertx() {try {var vertx = Function('return this')().require('vertx');vertxNext = vertx.runOnLoop || vertx.runOnContext;return useVertxTimer();} catch (e) {return useSetTimeout();}}var scheduleFlush = void 0;// Decide what async method to use to triggering processing of queued callbacks:if (isNode) {scheduleFlush = useNextTick();} else if (BrowserMutationObserver) {scheduleFlush = useMutationObserver();} else if (isWorker) {scheduleFlush = useMessageChannel();} else if (browserWindow === undefined && typeof require === 'function') {scheduleFlush = attemptVertx();} else {scheduleFlush = useSetTimeout();}function then(onFulfillment, onRejection) {var parent = this;var child = new this.constructor(noop);if (child[PROMISE_ID] === undefined) {makePromise(child);}var _state = parent._state;if (_state) {var callback = arguments[_state - 1];asap(function () {return invokeCallback(_state, child, callback, parent._result);});} else {subscribe(parent, child, onFulfillment, onRejection);}return child;}/**`Promise.resolve` returns a promise that will become resolved with thepassed `value`. It is shorthand for the following:```javascriptlet promise = new Promise(function(resolve, reject){resolve(1);});promise.then(function(value){// value === 1});```Instead of writing the above, your code now simply becomes the following:```javascriptlet promise = Promise.resolve(1);promise.then(function(value){// value === 1});```@method resolve@static@param {Any} value value that the returned promise will be resolved withUseful for tooling.@return {Promise} a promise that will become fulfilled with the given`value`*/function resolve$1(object) {/*jshint validthis:true */var Constructor = this;if (object && typeof object === 'object' && object.constructor === Constructor) {return object;}var promise = new Constructor(noop);resolve(promise, object);return promise;}var PROMISE_ID = Math.random().toString(36).substring(2);function noop() {}var PENDING = void 0;var FULFILLED = 1;var REJECTED = 2;var TRY_CATCH_ERROR = {error: null};function selfFulfillment() {return new TypeError("You cannot resolve a promise with itself");}function cannotReturnOwn() {return new TypeError('A promises callback cannot return that same promise.');}function getThen(promise) {try {return promise.then;} catch (error) {TRY_CATCH_ERROR.error = error;return TRY_CATCH_ERROR;}}function tryThen(then$$1, value, fulfillmentHandler, rejectionHandler) {try {then$$1.call(value, fulfillmentHandler, rejectionHandler);} catch (e) {return e;}}function handleForeignThenable(promise, thenable, then$$1) {asap(function (promise) {var sealed = false;var error = tryThen(then$$1, thenable, function (value) {if (sealed) {return;}sealed = true;if (thenable !== value) {resolve(promise, value);} else {fulfill(promise, value);}}, function (reason) {if (sealed) {return;}sealed = true;reject(promise, reason);}, 'Settle: ' + (promise._label || ' unknown promise'));if (!sealed && error) {sealed = true;reject(promise, error);}}, promise);}function handleOwnThenable(promise, thenable) {if (thenable._state === FULFILLED) {fulfill(promise, thenable._result);} else if (thenable._state === REJECTED) {reject(promise, thenable._result);} else {subscribe(thenable, undefined, function (value) {return resolve(promise, value);}, function (reason) {return reject(promise, reason);});}}function handleMaybeThenable(promise, maybeThenable, then$$1) {if (maybeThenable.constructor === promise.constructor && then$$1 === then && maybeThenable.constructor.resolve === resolve$1) {handleOwnThenable(promise, maybeThenable);} else {if (then$$1 === TRY_CATCH_ERROR) {reject(promise, TRY_CATCH_ERROR.error);TRY_CATCH_ERROR.error = null;} else if (then$$1 === undefined) {fulfill(promise, maybeThenable);} else if (isFunction(then$$1)) {handleForeignThenable(promise, maybeThenable, then$$1);} else {fulfill(promise, maybeThenable);}}}function resolve(promise, value) {if (promise === value) {reject(promise, selfFulfillment());} else if (objectOrFunction(value)) {handleMaybeThenable(promise, value, getThen(value));} else {fulfill(promise, value);}}function publishRejection(promise) {if (promise._onerror) {promise._onerror(promise._result);}publish(promise);}function fulfill(promise, value) {if (promise._state !== PENDING) {return;}promise._result = value;promise._state = FULFILLED;if (promise._subscribers.length !== 0) {asap(publish, promise);}}function reject(promise, reason) {if (promise._state !== PENDING) {return;}promise._state = REJECTED;promise._result = reason;asap(publishRejection, promise);}function subscribe(parent, child, onFulfillment, onRejection) {var _subscribers = parent._subscribers;var length = _subscribers.length;parent._onerror = null;_subscribers[length] = child;_subscribers[length + FULFILLED] = onFulfillment;_subscribers[length + REJECTED] = onRejection;if (length === 0 && parent._state) {asap(publish, parent);}}function publish(promise) {var subscribers = promise._subscribers;var settled = promise._state;if (subscribers.length === 0) {return;}var child = void 0,callback = void 0,detail = promise._result;for (var i = 0; i < subscribers.length; i += 3) {child = subscribers[i];callback = subscribers[i + settled];if (child) {invokeCallback(settled, child, callback, detail);} else {callback(detail);}}promise._subscribers.length = 0;}function tryCatch(callback, detail) {try {return callback(detail);} catch (e) {TRY_CATCH_ERROR.error = e;return TRY_CATCH_ERROR;}}function invokeCallback(settled, promise, callback, detail) {var hasCallback = isFunction(callback),value = void 0,error = void 0,succeeded = void 0,failed = void 0;if (hasCallback) {value = tryCatch(callback, detail);if (value === TRY_CATCH_ERROR) {failed = true;error = value.error;value.error = null;} else {succeeded = true;}if (promise === value) {reject(promise, cannotReturnOwn());return;}} else {value = detail;succeeded = true;}if (promise._state !== PENDING) {// noop} else if (hasCallback && succeeded) {resolve(promise, value);} else if (failed) {reject(promise, error);} else if (settled === FULFILLED) {fulfill(promise, value);} else if (settled === REJECTED) {reject(promise, value);}}function initializePromise(promise, resolver) {try {resolver(function resolvePromise(value) {resolve(promise, value);}, function rejectPromise(reason) {reject(promise, reason);});} catch (e) {reject(promise, e);}}var id = 0;function nextId() {return id++;}function makePromise(promise) {promise[PROMISE_ID] = id++;promise._state = undefined;promise._result = undefined;promise._subscribers = [];}function validationError() {return new Error('Array Methods must be provided an Array');}var Enumerator = function () {function Enumerator(Constructor, input) {this._instanceConstructor = Constructor;this.promise = new Constructor(noop);if (!this.promise[PROMISE_ID]) {makePromise(this.promise);}if (isArray(input)) {this.length = input.length;this._remaining = input.length;this._result = new Array(this.length);if (this.length === 0) {fulfill(this.promise, this._result);} else {this.length = this.length || 0;this._enumerate(input);if (this._remaining === 0) {fulfill(this.promise, this._result);}}} else {reject(this.promise, validationError());}}Enumerator.prototype._enumerate = function _enumerate(input) {for (var i = 0; this._state === PENDING && i < input.length; i++) {this._eachEntry(input[i], i);}};Enumerator.prototype._eachEntry = function _eachEntry(entry, i) {var c = this._instanceConstructor;var resolve$$1 = c.resolve;if (resolve$$1 === resolve$1) {var _then = getThen(entry);if (_then === then && entry._state !== PENDING) {this._settledAt(entry._state, i, entry._result);} else if (typeof _then !== 'function') {this._remaining--;this._result[i] = entry;} else if (c === Promise$2) {var promise = new c(noop);handleMaybeThenable(promise, entry, _then);this._willSettleAt(promise, i);} else {this._willSettleAt(new c(function (resolve$$1) {return resolve$$1(entry);}), i);}} else {this._willSettleAt(resolve$$1(entry), i);}};Enumerator.prototype._settledAt = function _settledAt(state, i, value) {var promise = this.promise;if (promise._state === PENDING) {this._remaining--;if (state === REJECTED) {reject(promise, value);} else {this._result[i] = value;}}if (this._remaining === 0) {fulfill(promise, this._result);}};Enumerator.prototype._willSettleAt = function _willSettleAt(promise, i) {var enumerator = this;subscribe(promise, undefined, function (value) {return enumerator._settledAt(FULFILLED, i, value);}, function (reason) {return enumerator._settledAt(REJECTED, i, reason);});};return Enumerator;}();/**`Promise.all` accepts an array of promises, and returns a new promise whichis fulfilled with an array of fulfillment values for the passed promises, orrejected with the reason of the first passed promise to be rejected. It casts allelements of the passed iterable to promises as it runs this algorithm.Example:```javascriptlet promise1 = resolve(1);let promise2 = resolve(2);let promise3 = resolve(3);let promises = [ promise1, promise2, promise3 ];Promise.all(promises).then(function(array){// The array here would be [ 1, 2, 3 ];});```If any of the `promises` given to `all` are rejected, the first promisethat is rejected will be given as an argument to the returned promises'srejection handler. For example:Example:```javascriptlet promise1 = resolve(1);let promise2 = reject(new Error("2"));let promise3 = reject(new Error("3"));let promises = [ promise1, promise2, promise3 ];Promise.all(promises).then(function(array){// Code here never runs because there are rejected promises!}, function(error) {// error.message === "2"});```@method all@static@param {Array} entries array of promises@param {String} label optional string for labeling the promise.Useful for tooling.@return {Promise} promise that is fulfilled when all `promises` have beenfulfilled, or rejected if any of them become rejected.@static*/function all(entries) {return new Enumerator(this, entries).promise;}/**`Promise.race` returns a new promise which is settled in the same way as thefirst passed promise to settle.Example:```javascriptlet promise1 = new Promise(function(resolve, reject){setTimeout(function(){resolve('promise 1');}, 200);});let promise2 = new Promise(function(resolve, reject){setTimeout(function(){resolve('promise 2');}, 100);});Promise.race([promise1, promise2]).then(function(result){// result === 'promise 2' because it was resolved before promise1// was resolved.});````Promise.race` is deterministic in that only the state of the firstsettled promise matters. For example, even if other promises given to the`promises` array argument are resolved, but the first settled promise hasbecome rejected before the other promises became fulfilled, the returnedpromise will become rejected:```javascriptlet promise1 = new Promise(function(resolve, reject){setTimeout(function(){resolve('promise 1');}, 200);});let promise2 = new Promise(function(resolve, reject){setTimeout(function(){reject(new Error('promise 2'));}, 100);});Promise.race([promise1, promise2]).then(function(result){// Code here never runs}, function(reason){// reason.message === 'promise 2' because promise 2 became rejected before// promise 1 became fulfilled});```An example real-world use case is implementing timeouts:```javascriptPromise.race([ajax('foo.json'), timeout(5000)])```@method race@static@param {Array} promises array of promises to observeUseful for tooling.@return {Promise} a promise which settles in the same way as the first passedpromise to settle.*/function race(entries) {/*jshint validthis:true */var Constructor = this;if (!isArray(entries)) {return new Constructor(function (_, reject) {return reject(new TypeError('You must pass an array to race.'));});} else {return new Constructor(function (resolve, reject) {var length = entries.length;for (var i = 0; i < length; i++) {Constructor.resolve(entries[i]).then(resolve, reject);}});}}/**`Promise.reject` returns a promise rejected with the passed `reason`.It is shorthand for the following:```javascriptlet promise = new Promise(function(resolve, reject){reject(new Error('WHOOPS'));});promise.then(function(value){// Code here doesn't run because the promise is rejected!}, function(reason){// reason.message === 'WHOOPS'});```Instead of writing the above, your code now simply becomes the following:```javascriptlet promise = Promise.reject(new Error('WHOOPS'));promise.then(function(value){// Code here doesn't run because the promise is rejected!}, function(reason){// reason.message === 'WHOOPS'});```@method reject@static@param {Any} reason value that the returned promise will be rejected with.Useful for tooling.@return {Promise} a promise rejected with the given `reason`.*/function reject$1(reason) {/*jshint validthis:true */var Constructor = this;var promise = new Constructor(noop);reject(promise, reason);return promise;}function needsResolver() {throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');}function needsNew() {throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");}/**Promise objects represent the eventual result of an asynchronous operation. Theprimary way of interacting with a promise is through its `then` method, whichregisters callbacks to receive either a promise's eventual value or the reasonwhy the promise cannot be fulfilled.Terminology------------ `promise` is an object or function with a `then` method whose behavior conforms to this specification.- `thenable` is an object or function that defines a `then` method.- `value` is any legal JavaScript value (including undefined, a thenable, or a promise).- `exception` is a value that is thrown using the throw statement.- `reason` is a value that indicates why a promise was rejected.- `settled` the final resting state of a promise, fulfilled or rejected.A promise can be in one of three states: pending, fulfilled, or rejected.Promises that are fulfilled have a fulfillment value and are in the fulfilledstate.  Promises that are rejected have a rejection reason and are in therejected state.  A fulfillment value is never a thenable.Promises can also be said to *resolve* a value.  If this value is also apromise, then the original promise's settled state will match the value'ssettled state.  So a promise that *resolves* a promise that rejects willitself reject, and a promise that *resolves* a promise that fulfills willitself fulfill.Basic Usage:------------```jslet promise = new Promise(function(resolve, reject) {// on successresolve(value);// on failurereject(reason);});promise.then(function(value) {// on fulfillment}, function(reason) {// on rejection});```Advanced Usage:---------------Promises shine when abstracting away asynchronous interactions such as`XMLHttpRequest`s.```jsfunction getJSON(url) {return new Promise(function(resolve, reject){let xhr = new XMLHttpRequest();xhr.open('GET', url);xhr.onreadystatechange = handler;xhr.responseType = 'json';xhr.setRequestHeader('Accept', 'application/json');xhr.send();function handler() {if (this.readyState === this.DONE) {if (this.status === 200) {resolve(this.response);} else {reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));}}};});}getJSON('/posts.json').then(function(json) {// on fulfillment}, function(reason) {// on rejection});```Unlike callbacks, promises are great composable primitives.```jsPromise.all([getJSON('/posts'),getJSON('/comments')]).then(function(values){values[0] // => postsJSONvalues[1] // => commentsJSONreturn values;});```@class Promise@param {Function} resolverUseful for tooling.@constructor*/var Promise$2 = function () {function Promise(resolver) {this[PROMISE_ID] = nextId();this._result = this._state = undefined;this._subscribers = [];if (noop !== resolver) {typeof resolver !== 'function' && needsResolver();this instanceof Promise ? initializePromise(this, resolver) : needsNew();}}/**The primary way of interacting with a promise is through its `then` method,which registers callbacks to receive either a promise's eventual value or thereason why the promise cannot be fulfilled.```jsfindUser().then(function(user){// user is available}, function(reason){// user is unavailable, and you are given the reason why});```Chaining--------The return value of `then` is itself a promise.  This second, 'downstream'promise is resolved with the return value of the first promise's fulfillmentor rejection handler, or rejected if the handler throws an exception.```jsfindUser().then(function (user) {return user.name;}, function (reason) {return 'default name';}).then(function (userName) {// If `findUser` fulfilled, `userName` will be the user's name, otherwise it// will be `'default name'`});findUser().then(function (user) {throw new Error('Found user, but still unhappy');}, function (reason) {throw new Error('`findUser` rejected and we're unhappy');}).then(function (value) {// never reached}, function (reason) {// if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.// If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.});```If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.```jsfindUser().then(function (user) {throw new PedagogicalException('Upstream error');}).then(function (value) {// never reached}).then(function (value) {// never reached}, function (reason) {// The `PedgagocialException` is propagated all the way down to here});```Assimilation------------Sometimes the value you want to propagate to a downstream promise can only beretrieved asynchronously. This can be achieved by returning a promise in thefulfillment or rejection handler. The downstream promise will then be pendinguntil the returned promise is settled. This is called *assimilation*.```jsfindUser().then(function (user) {return findCommentsByAuthor(user);}).then(function (comments) {// The user's comments are now available});```If the assimliated promise rejects, then the downstream promise will also reject.```jsfindUser().then(function (user) {return findCommentsByAuthor(user);}).then(function (comments) {// If `findCommentsByAuthor` fulfills, we'll have the value here}, function (reason) {// If `findCommentsByAuthor` rejects, we'll have the reason here});```Simple Example--------------Synchronous Example```javascriptlet result;try {result = findResult();// success} catch(reason) {// failure}```Errback Example```jsfindResult(function(result, err){if (err) {// failure} else {// success}});```Promise Example;```javascriptfindResult().then(function(result){// success}, function(reason){// failure});```Advanced Example--------------Synchronous Example```javascriptlet author, books;try {author = findAuthor();books  = findBooksByAuthor(author);// success} catch(reason) {// failure}```Errback Example```jsfunction foundBooks(books) {}function failure(reason) {}findAuthor(function(author, err){if (err) {failure(err);// failure} else {try {findBoooksByAuthor(author, function(books, err) {if (err) {failure(err);} else {try {foundBooks(books);} catch(reason) {failure(reason);}}});} catch(error) {failure(err);}// success}});```Promise Example;```javascriptfindAuthor().then(findBooksByAuthor).then(function(books){// found books}).catch(function(reason){// something went wrong});```@method then@param {Function} onFulfilled@param {Function} onRejectedUseful for tooling.@return {Promise}*//**`catch` is simply sugar for `then(undefined, onRejection)` which makes it the sameas the catch block of a try/catch statement.```jsfunction findAuthor(){throw new Error('couldn't find that author');}// synchronoustry {findAuthor();} catch(reason) {// something went wrong}// async with promisesfindAuthor().catch(function(reason){// something went wrong});```@method catch@param {Function} onRejectionUseful for tooling.@return {Promise}*/Promise.prototype.catch = function _catch(onRejection) {return this.then(null, onRejection);};/**`finally` will be invoked regardless of the promise's fate just as nativetry/catch/finally behavesSynchronous example:```jsfindAuthor() {if (Math.random() > 0.5) {throw new Error();}return new Author();}try {return findAuthor(); // succeed or fail} catch(error) {return findOtherAuther();} finally {// always runs// doesn't affect the return value}```Asynchronous example:```jsfindAuthor().catch(function(reason){return findOtherAuther();}).finally(function(){// author was either found, or not});```@method finally@param {Function} callback@return {Promise}*/Promise.prototype.finally = function _finally(callback) {var promise = this;var constructor = promise.constructor;return promise.then(function (value) {return constructor.resolve(callback()).then(function () {return value;});}, function (reason) {return constructor.resolve(callback()).then(function () {throw reason;});});};return Promise;}();Promise$2.prototype.then = then;Promise$2.all = all;Promise$2.race = race;Promise$2.resolve = resolve$1;Promise$2.reject = reject$1;Promise$2._setScheduler = setScheduler;Promise$2._setAsap = setAsap;Promise$2._asap = asap;/*global self*/function polyfill() {var local = void 0;if (typeof global !== 'undefined') {local = global;} else if (typeof self !== 'undefined') {local = self;} else {try {local = Function('return this')();} catch (e) {throw new Error('polyfill failed because global object is unavailable in this environment');}}var P = local.Promise;if (P) {var promiseToString = null;try {promiseToString = Object.prototype.toString.call(P.resolve());} catch (e) {// silently ignored}if (promiseToString === '[object Promise]' && !P.cast) {return;}}local.Promise = Promise$2;}// Strange compat..Promise$2.polyfill = polyfill;Promise$2.Promise = Promise$2;Promise$2.polyfill();return Promise$2;})));//# sourceMappingURL=es6-promise.auto.map

引入进去

var Promise = require('./es6-promise.auto.js');


然后定义一个请求的函数

var app = getApp()var Promise = require('./es6-promise.auto.js');function request(url, header, method, params, t) {wx.showLoading({title: '正在加载',mask: true})console.log('请求地址', url)console.log('请求头部', header)console.log('请求方式', method)console.log('请求参数', params)let promisevariable = new Promise(function (resolve, reject) {wx.request({url: url,header: header,data: params,method: method,success: function (res) {console.log('得到的参数', res)if ('定义的成功') {resolve(res)}wx.hideLoading()},fail(err) {wx.showToast({title: err,icon: 'none'})}});});return promisevariable;
}
// 1.通过module.exports方式提供给外部调用
module.exports = {request: request,
}

引入到使用的页面里

var http = require("请求函数的路径");

使用时

    let that = thislet url = ''let params = {}let header = {}let method = 'post'await http.request(url, header, method, params, t).then(res => {console.log(res)})

就可以使用了

微信小程序 请求函数 同步封装方法相关推荐

  1. 微信小程序请求函数的封装

    每次从网页中请求函数都需要书写一次请求,若请求的数据多了,代码会变得繁杂从而难以维护. 这时我们可以通过封装来进行更加便捷的书写,方式如下: 1.在 util.js 文件下封装要用到的值进一个函数里面 ...

  2. 微信小程序常用函数的封装

    微信小程序开发交流qq群   173683895    承接微信小程序开发.扫码加微信. 在小程序里面经常会反复用到一些方法,例如: 1.网络请求, 2.时间戳转换成日期时间, 3.根据数组中的对象的 ...

  3. 如何同步微信信息php,微信小程序中实现同步请求的方法

    本篇文章给大家带来的内容是关于微信小程序中实现同步请求的方法,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 微信小程序默认是用同步请求的,但有些时候需要数据的同步请求,可使用的方法有 ...

  4. 微信小程序请求及封装请求方式

    一.微信小程序请求实现方式 小程序发起网络请求 需用到 wx.request(Object object) 例如:wx.request({url: 'test.php', //仅为示例,并非真实的接口 ...

  5. 【 微信小程序请求封装】【进阶版】处理401请求token过期--重新登录--重新发起刚才过期的请求

    微信小程序请求封装(拦截器):处理请求过期–重新登录–重新发起刚才过期的请求 env.js //这里使用的接口呢都是自己模拟的,可以根据自己的需求进行添加module.exports={//开发环境的 ...

  6. 微信小程序云函数使用教程【超详细】

    背景需求 在本人的项目中,需要调用一个http的接口,而微信小程序所有的网络请求都得使用https,因而需要一个中转站,使得在正式发布的时候可以使用http接口.(在调试环境下,只要在本地设置里勾选& ...

  7. 微信小程序云函数操作云数据库Mysql

    微信小程序云函数操作云数据库Mysql 参考一 参考二 云函数是一段运行在云端的代码,无需管理服务器,在开发工具内编写.一键上传部署即可运行后端代码. 小程序内提供了专门用于云函数调用的 API.开发 ...

  8. 微信小程序 wx.request 的封装

    自学转行到前端也已近两年,也算是简书和掘金的忠实粉丝,但是以前一直惜字如金(实在是胆子小,水平又低),现在我决定视金钱如粪土(就只是脸皮厚了,水平就那样),好了废话不多说,切入主题,最近自己尝试了一下 ...

  9. 分享下自己写的一个微信小程序请求远程数据加载到页面的代码

    分享下自己写的一个微信小程序请求远程数据加载到页面的代码 1  思路整理 就是页面加载完毕的时候  请求远程接口,然后把数据赋值给页面的变量 ,然后列表循环 2 js相关代码  我是改的 onload ...

最新文章

  1. Dubbo 源码分析 - 服务导出
  2. 当变化来临,PM的心态和节奏如何把握?
  3. sql多字段求和降序排序_elasticsearch基础笔记11-搜索排序
  4. SAP 电商云 Spartacus UI 根据 CMS Component uid 获取数据
  5. 遇到可爱女生如何搭讪?
  6. linux协议栈劫持,Linux系统优化之TCP协议栈优化-基本篇1
  7. linux用户怎么归纳到组,Linux用户和组命令总结
  8. TCP/UDP通信解疑
  9. 程序的图标无法改变_想体验程序猿日常工作的快乐吗?来玩国产烧脑益智游戏《异常》...
  10. 6.微服务:从设计到部署 --- 选择部署策略
  11. 给一个链表,若其中包含环,请找出该链表的环的入口结点,否则,输出null。(C++实现,非常简单明了)
  12. JS自定义表单提交处理方案
  13. Intellij idea 运行 vertx examples
  14. APK应用程序的解包、修改、编辑、打包及应用(一)
  15. catia中尺子没了怎么调出来,【答疑】草图大师sketchup的尺子快捷键是什么呀? - 羽兔网问答...
  16. (java)word转html并提取word中的目录结构树生成到html页面中的左边树
  17. leetcode--打家劫舍
  18. 时间触发协议(Time triggered protocol)概述
  19. 让Oracle高效并行执行的13个必备知识点
  20. centos7 挂载 硬盘 shell 懒人系列-2

热门文章

  1. 不要踏入window这条贼船 java也不要碰
  2. 中山大学计算机在职研究生分数线,中山大学在职研究生的考试分数线是多少?...
  3. Codeforces 1325C. Ehab and Path-etic MEXs(构造)
  4. Python实现植物大战僵尸
  5. \newpage与\clearpage的区别以及分页断行的多种方式,如何构造首字下沉的效果?
  6. K 个一组翻转链表(递归,Kotlin)
  7. PTA-基础编程题目集-7-1 厘米换算英尺英寸
  8. Android调用系统相机拍照像素太低以及内存溢出问题
  9. 今日雨水——草木萌動
  10. 维护华为服务器的好工具KVM