是小程序实例化后

读入内存

还是每次调用从文件系统读取

https://github.com/Tencent/wepy/blob/bd0003dca2bfb9581134e1b05d4aa1d80fc53858/packages/wepy-web/src/wx.js

/**
* Tencent is pleased to support the open source community by making WePY available.
* Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/ import Vue from 'vue';
import axios from 'axios';
import {resolveQuery} from './helper/query';
import {browser, system} from './helper/device'; const callback = (type, o, name, data) => {
if (typeof o[type] === 'function') {
setTimeout(() => {
if (name === 'login') {
o[type].call(wx, {errMsg: name + ':' + (type === 'fail' ? 'fail' : 'ok'), code: data.code, data: data});
} else if (name === 'getSystemInfo') {
o[type].call(wx, data);
} else {
o[type].call(wx, {errMsg: name + ':' + (type === 'fail' ? 'fail' : 'ok'), data: data});
}
}, 0);
}
} let wx = window.wx || {}; wx.login = wx.login || function login (o) {
console.error('wx.login is only implemented in browser');
}; /*** Storage ***/
wx.getStorageSync = wx.getStorageSync || function getStorageSync (v) {
let rst = window.localStorage.getItem(v);
try {
rst = JSON.parse(rst);
} catch (e) {
}
return rst;
};
wx.getStorage = wx.getStorage || function getStorage (o) {
let rst = wx.getStorageSync(o.key);
callback('success', o, 'getStorage', rst);
callback('complete', o, 'getStorage', rst);
};
wx.setStorageSync = wx.setStorageSync || function setStorageSync (k, d) {
if (typeof d !== 'string') {
d = JSON.stringify(d);
}
window.localStorage.setItem(k, d);
};
wx.setStorage = wx.setStorage || function setStorage (o) {
let rst;
try {
rst = this.setStorageSync(o.key, o.data);
callback('success', o, 'getStorage', rst);
} catch (e) {
callback('fail', o, 'getStorage', rst);
}
callback('complete', o, 'getStorage', rst);
};
wx.getStorageInfoSync = wx.getStorageInfoSync || function getStorageInfoSync () {
let MAX_SIZE = 5 * 1024;
let keys = Object.keys(window.localStorage);
return {
currentSize: 1,
keys: keys,
limitSize: MAX_SIZE
};
};
wx.getStorageInfo = wx.getStorageInfo || function getStorageInfo (o) {
let rst = this.getStorageInfoSync();
callback('success', o, 'getStorageInfo', rst);
callback('complete', o, 'getStorageInfo', rst);
};
wx.removeStorageSync = wx.removeStorageSync || function removeStorageSync (k) {
window.localStorage.removeItem(k);
};
wx.removeStorage = wx.removeStorage || function removeStorage (o) {
let rst;
try {
rst = this.removeStorage(o.key);
callback('success', o, 'getStorage', rst);
} catch (e) {
callback('fail', o, 'getStorage', rst);
}
callback('complete', o, 'getStorage', rst);
};
wx.clearStorageSync = wx.clearStorageSync || function clearStorageSync () {
window.localStorage.clear();
};
wx.clearStorage = wx.clearStorage || function clearStorage () {
let rst;
try {
rst = this.clearStorage();
} catch (e) {
}
}; /***** Navigate ******/
wx.navigateTo = wx.navigateTo || function navigateTo (o) {
window.$router.go(o.url);
};
wx.redirectTo = wx.redirectTo || function redirectTo (o) {
window.$router.go(o.url);
};
wx.switchTab = wx.switchTab || function switchTab (o) {
window.$router.go(o.url);
};
wx.navigateBack = wx.navigateBack || function navigateBack (o) {
if (!o) {
o = {};
}
if (o.delta)
o.delta = -1;
window.$router.go(o.delta);
}; /***** System ******/
wx.getSystemInfoSync = wx.getSystemInfoSync || function getSystemInfoSync () {
return {
SDKVersion: '0.0.0',
language: '-',
model: browser(),
pixelRatio: 0,
platform: system(),
screenHeight: window.screen.height,
screenWidth: window.screen.width,
system: system(),
version: '0.0.0',
windowHeight: window.innerHeight,
windowWidth: window.innerWidth
}
};
wx.getSystemInfo = wx.getSystemInfo || function getSystemInfo (o) {
let rst = this.getSystemInfoSync();
callback('success', o, 'getSystemInfo', rst);
callback('complete', o, 'getSystemInfo', rst);
};
wx.canIUse = wx.canIUse || function canIUse () {
return true;
}; /****** Network ***********/
wx.getNetworkType = wx.getNetworkType || function getNetworkType () {
return 'unkown';
}; /****** NavigationBar *******/
wx.setNavigationBarTitle = wx.setNavigationBarTitle || function setNavigationBarTitle (o) {
document.title = o.title;
callback('success', o, 'setNavigationBarTitle', null);
callback('complete', o, 'setNavigationBarTitle', null);
}; wx.makePhoneCall = wx.makePhoneCall || function makePhoneCall (o) {
window.location = 'tel:' + o.phoneNumber;
callback('success', o, 'makePhoneCall', null);
callback('complete', o, 'makePhoneCall', null);
}; wx.hideKeyboard = wx.hideKeyboard || function hideKeyboard () {
// http://stackoverflow.com/questions/8335834/how-can-i-hide-the-android-keyboard-using-javascript
setTimeout(() => {
let field = document.createElement('input');
field.setAttribute('type', 'text');
field.setAttribute('style', 'position:absolute; top: 0px; opacity: 0; -webkit-user-modify: read-write-plaintext-only; left:0px;');
document.body.appendChild(field); field.onfocus = () => {
setTimeout(() => {
field.setAttribute('style', 'display:none;');
setTimeout(() => {
document.body.removeChild(field);
document.body.focus();
}, 14); }, 200);
};
field.focus();
}, 50);
}; ['getUserInfo', 'switchTab', 'showNavigationBarLoading', 'hideNavigationBarLoading', 'createAnimation', 'requestPayment', 'chooseImage', 'showModal', 'showToast', 'showActionSheet'].forEach(k => {
if (!wx[k]) {
wx[k] = (o = {}) => {
console.error(`wx.${k} is not supported in browser or you did add it in config.`);
callback('fail', o, k, null);
callback('complete', o, k, null);
};
}
}); wx.request = wx.request ? wx.request : function request (options) {
let handlers = {};
['success', 'fail', 'complete', 'beforeAll', 'beforeSuccess', 'afterSuccess', 'beforeCancel', 'cancel', 'afterCancel', 'beforeFail', 'afterFail', 'afterAll'].forEach(k => {
handlers[k] = options[k];
delete options[k];
});
let rst = {errMsg: 'request', statusCode: 0, data: undefined};
if (!options.method || options.method.toLowerCase() === 'get') {
options.params = options.data;
delete options.data;
}
axios(options).then(res => {
rst.errMsg = rst.errMsg + ':ok';
rst.statusCode = res.status;
rst.data = res.data; // WAService.js
if (typeof handlers.beforeAll === 'function') {
handlers.beforeAll(res);
}
if (typeof handlers.beforeSuccess === 'function') {
handlers.beforeSuccess(res);
}
if (typeof handlers.success === 'function') {
handlers.success(res);
}
if (typeof handlers.afterSuccess === 'function') {
handlers.afterSuccess(res);
}
if (typeof handlers.complete === 'function') {
handlers.complete(res);
}
if (typeof handlers.afterAll === 'function') {
handlers.afterAll(res);
}
}).catch(res => {
if (typeof handlers.beforeAll === 'function') {
handlers.beforeAll(res);
}
if (axios.isCancel(res)) {
rst.errMsg = rst.errMsg + ':cancel';
if (typeof handlers.fail === 'function') {
handlers.fail(res);
}
if (typeof handlers.beforeCancel === 'function') {
handlers.beforeCancel(res);
}
if (typeof handlers.cancel === 'function') {
handlers.cancel(res);
}
if (typeof handlers.afterCancel === 'function') {
handlers.afterCancel(res);
}
} else {
rst.errMsg = rst.errMsg + ':fail';
if (typeof handlers.beforeFail === 'function') {
handlers.beforeFail(res);
}
if (typeof handlers.fail === 'function') {
handlers.fail(res);
}
if (typeof handlers.afterFail === 'function') {
handlers.afterFail(res);
}
}
rst.data = res;
if (typeof handlers.complete === 'function') {
handlers.complete(res);
}
if (typeof handlers.afterAll === 'function') {
handlers.afterAll(res);
}
})
}; if (typeof window !== 'undefined') {
window.getApp = () => {
return Vue;
}; window.getCurrentPages = () => {
if (wx._currentPage)
return [wx._currentPage];
else
return [wx._currentPages[0]];
};
} window.wx = wx; export default wx;

数据缓存 · 小程序 https://mp.weixin.qq.com/debug/wxadoc/dev/api/data.html#wxremovestoragesynckey

Bug & Tip

  1. tip: 本地数据存储的大小限制为 10MB

最新文章

  1. debian下Apache和tomcat整合(使用apt工具)
  2. 【centOS】账号管理
  3. 搜集资料&安装环境
  4. c数据结构 顺序表和链表 相关操作
  5. RedHat 6.7 Enterprise x64环境下使用RHCS部署Oracle 11g R2双机HA
  6. OpenSSL密码算法库: MD5示例小程序
  7. Redis中统计各种数据大小的方法
  8. stm32 加入 USE_STDPERIPH_DRIVER、STM32F10X_HD的原因
  9. 实现手机扫描二维码页面登录,类似web微信-第三篇,手机客户端
  10. css标签选择器的优先级
  11. mysql kill操作
  12. [Angular 2] Understanding OpaqueToken
  13. Websocket协议之php实现
  14. 滑雪(POJ 1088 记忆化搜索)
  15. Andorid开发中如何去除标题栏title
  16. Spring的事务管理(理论篇,下篇提供代码实现)
  17. jwt验证登录信息
  18. iOS客户端图片智能裁剪
  19. UVA11324 The Largest Clique (强连通缩点+DP最长路)
  20. 20155208徐子涵 Exp5 MSF基础应用

热门文章

  1. ui设计的好网站(转载)
  2. Network | 协议栈
  3. C++输入和输出中进制问题
  4. Linux下搭建PHP开发环境(LAMP)
  5. nohup 输出重定向
  6. Linux学习之十六-Linux用户管理
  7. 粗略。。Java项目设计模式之笔记----studying
  8. Mark一下, dp状态转移方程写对,可是写代码都错,poj 1651 poj 1179
  9. [集合]解决system权限3389无法添加的用户情况
  10. 聚合数据Android SDK 12306火车票查询订票演示示例