update Time

This commit is contained in:
梁灏 2018-05-17 18:06:42 +08:00
parent 7f9ea0dc5e
commit b8509c593a

View file

@ -1,8 +1,62 @@
<template> <template>
<span>time</span> <span :class="classes" @click="handleClick">time</span>
</template> </template>
<script> <script>
export default { import { oneOf } from '../../utils/assist';
const prefixCls = 'ivu-time';
export default {
name: 'Time',
props: {
time: {
type: [String, Number, Date],
required: true
},
type: {
type: String,
validator (value) {
return oneOf(value, ['relative', 'date', 'datetime']);
},
default: 'relative'
},
hash: {
type: String,
default: ''
},
interval: {
type: Number,
default: 60
}
},
data () {
return {
date: ''
};
},
computed: {
classes () {
return [
`${prefixCls}`,
{
[`${prefixCls}-with-hash`]: this.hash
}
];
}
},
methods: {
handleClick () {
if (this.hash !== '') window.location.hash = this.hash;
}
},
mounted () {
this.setTime();
this.timer = setInterval(() => {
this.setTime();
}, 1000 * this.interval);
},
beforeDestroy () {
if (this.timer) clearInterval(this.timer);
}
}; };
</script> </script>