fix Time component can't update when time prop updated.

https://segmentfault.com/q/1010000021110866
https://run.iviewui.com/GRzcErZn
This commit is contained in:
Richex 2019-11-28 21:09:49 +08:00
parent 410a5fbca7
commit 0e7ca485c6
2 changed files with 17 additions and 1 deletions

View file

@ -1,5 +1,7 @@
<template>
<div>
<Button @click="testUpdate()">Update Test</Button>
<br>
<Time :time="time1" />
<br>
<Time :time="time2" />
@ -10,6 +12,8 @@
</div>
</template>
<script>
const baseTime = parseInt(Date.now() / 10000000) * 10000000
export default {
data () {
return {
@ -18,6 +22,12 @@
time3: (new Date()).getTime() - 1 * 1000,
time4: (new Date()).getTime() - 86400 * 60 * 1000,
};
},
methods: {
testUpdate() {
this.time1 = parseInt(baseTime + Math.random() * 10000000)
}
}
};
</script>

View file

@ -49,6 +49,12 @@
];
}
},
watch: {
time () {
// https://segmentfault.com/q/1010000021110866
if (!isServer) this.setTime()
}
},
methods: {
handleClick () {
if (this.hash !== '') window.location.hash = this.hash;
@ -96,4 +102,4 @@
if (this.timer) clearInterval(this.timer);
}
};
</script>
</script>