«

mpvue商品详情页面上次数据缓存

emer 发布于 2018-9-20 10:31   3550 次阅读     


cnpm install mpvue-page-factory

将main.js app.$mount()改为


import pageFactory from 'mpvue-page-factory'
import App from './index'
Page(pageFactory(App))

https://github.com/HelloZJW/mpvue-page-factory


或者


mpvue 页面切换数据缓存解决


onLoad () { Object.assign(this.$data, this.$options.data()) }


const dataArr = []

export default {
  onLoad() {
    Object.assign(this.$data, this.$options.data())
    // fetch some data
    dataArr.push({ ...this.$data })
  },
  onUnload() {
    dataArr.pop()
    const dataNum = dataArr.length
    if (!dataNum) return
    Object.assign(this.$data, dataArr[dataNum - 1])
  },
}