UNPKG

512 BJavaScriptView Raw
1// plugin/pages.js
2// 缓存pageModel,一个简要实现
3export default class PM {
4 constructor() {
5 this.$$cache = {}
6 }
7
8 add(pageModel) {
9 let pagePath = this._getPageModelPath(pageModel)
10 this.$$cache[pagePath] = pageModel
11 }
12
13 get(pagePath) {
14 return this.$$cache[pagePath]
15 }
16
17 delete(pageModel) {
18 try {
19 delete this.$$cache[this._getPageModelPath(pageModel)]
20 } catch (e) {
21 }
22 }
23
24 _getPageModelPath(page) {
25 // 关键点
26 return page.$wxpage.__route__
27 }
28 }