This commit is contained in:
parent
03aa56e320
commit
67b5fc1b20
|
@ -3,11 +3,17 @@ import util from '../../utils/util'
|
|||
import store from '../../store'
|
||||
|
||||
create(store, {
|
||||
data : {
|
||||
test: 'test data'
|
||||
},
|
||||
onLoad: function () {
|
||||
this.store.data.logs = (wx.getStorageSync('logs') || []).map(log => {
|
||||
return util.formatTime(new Date(log))
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
this.oData.test = 'test this.oData.test change'
|
||||
}, 1000)
|
||||
|
||||
setTimeout(() => {
|
||||
this.store.data.logs[0] = 'Changed!'
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
<text class="user-motto">{{store.motto}}</text>
|
||||
<text class="user-motto">-{{store.reverseMotto}}</text>
|
||||
</view>
|
||||
|
||||
<view class="usermotto">
|
||||
<text class="user-motto">{{test}}</text>
|
||||
</view>
|
||||
<block wx:for="{{store.logs}}" wx:for-item="log">
|
||||
<text class="log-item">{{index + 1}}. {{log}}</text>
|
||||
</block>
|
||||
|
|
|
@ -110,9 +110,19 @@ function create(store, option) {
|
|||
option.onLoad = function (e) {
|
||||
this.store = store
|
||||
|
||||
this.context = option.context
|
||||
const temp = option.data.store
|
||||
delete option.data.store
|
||||
this.oData = JSON.parse(JSON.stringify(option.data))
|
||||
if (!option.data.___walked) {
|
||||
walk(option.data, true)
|
||||
}
|
||||
observe(this, option.data)
|
||||
option.data.store = temp
|
||||
|
||||
store.instances[this.route] = []
|
||||
store.instances[this.route].push(this)
|
||||
if (!option.data.___walked) {
|
||||
if (!option.data.store.___walked) {
|
||||
walk(this.store.data)
|
||||
}
|
||||
this.setData.call(this, option.data)
|
||||
|
@ -122,14 +132,15 @@ function create(store, option) {
|
|||
} else {
|
||||
const ready = store.ready
|
||||
store.ready = function () {
|
||||
this.page = getCurrentPages()[getCurrentPages().length - 1]
|
||||
this.store = this.page.store
|
||||
const page = getCurrentPages()[getCurrentPages().length - 1]
|
||||
this.context = store.context || page.context
|
||||
this.store = page.store
|
||||
|
||||
store.data = store.data || {}
|
||||
store.data.store = this.store.data
|
||||
this.setData.call(this, store.data)
|
||||
|
||||
this.store.instances[this.page.route].push(this)
|
||||
this.store.instances[page.route].push(this)
|
||||
ready && ready.call(this)
|
||||
}
|
||||
Component(store)
|
||||
|
|
Loading…
Reference in New Issue