<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                [TOC] ## cache.js > 存放路徑 /common/cache.js ~~~ /** * 緩存數據優化 * var cache = require('utils/cache.js'); * import cache from '../cache' * 使用方法 【 * 一、設置緩存 * string cache.put('k', 'string你好啊'); * json cache.put('k', { "b": "3" }, 2); * array cache.put('k', [1, 2, 3]); * boolean cache.put('k', true); * 二、讀取緩存 * 默認值 cache.get('k') * string cache.get('k', '你好') * json cache.get('k', { "a": "1" }) * 三、移除/清理 * 移除: cache.remove('k'); * 清理:cache.clear(); * 】 * @type {String} */ var postfix = '_xjsU'; // 緩存前綴 /** * 設置緩存 * @param {[type]} k [鍵名] * @param {[type]} v [鍵值] * @param {[type]} t [時間、單位秒] */ function set(k, v, t) { uni.setStorageSync(k, v) var seconds = parseInt(t); if (seconds > 0) { var timestamp = Date.parse(new Date()); timestamp = timestamp / 1000 + seconds; uni.setStorageSync(k + postfix, timestamp + "") } else { uni.removeStorageSync(k + postfix) } } /** * 獲取緩存 * @param {[type]} k [鍵名] * @param {[type]} def [獲取為空時默認] */ function get(k, def) { var deadtime = parseInt(uni.getStorageSync(k + postfix)) if (deadtime) { if (parseInt(deadtime) < Date.parse(new Date()) / 1000) { if (def) { return def; } else { return false; } } } var res = uni.getStorageSync(k); if (res) { return res; } else { if (def == undefined || def == "") { def = false; } return def; } } function remove(k) { uni.removeStorageSync(k); uni.removeStorageSync(k + postfix); } /** * 清理所有緩存 * @return {[type]} [description] */ function clear() { uni.clearStorageSync(); } module.exports = { set: set, get: get, remove: remove, clear: clear } ~~~ ## main.js 中注冊該方法 > 路徑 /main.js ~~~ import Vue from 'vue' import App from './App' import cache from './common/cache.js' Vue.config.productionTip = false Vue.prototype.$cache = cache App.mpType = 'app' const app = new Vue({ ...App }) app.$mount() ~~~ ## 客戶端調用 ~~~ <template> <view> <button type="default" @tap="setCache">設置緩存</button> <button type="default" @tap="getCache">獲取緩存</button> <button type="default" @tap="clearCache">刪除緩存</button> </view> </template> <script> export default { methods: { setCache: function(e) { this.$cache.set('name', 'haha123'); }, getCache: function(e) { let name = this.$cache.get('name'); console.log("name is : " + name) }, clearCache: function(e) { this.$cache.clear(); }, } } </script> ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看