添加组件等
This commit is contained in:
55
miniprogram/pages/components/date-now/date-now.ts
Normal file
55
miniprogram/pages/components/date-now/date-now.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { formatTime } from '@/utils/util';
|
||||
|
||||
Component({
|
||||
options: { multipleSlots: true },
|
||||
/**
|
||||
* 组件的属性列表
|
||||
*/
|
||||
properties: {},
|
||||
|
||||
lifetimes: {
|
||||
attached() {
|
||||
// console.log('attached-----');
|
||||
},
|
||||
detached() {
|
||||
clearInterval(this.data.timer);
|
||||
},
|
||||
},
|
||||
pageLifetimes: {
|
||||
show() {
|
||||
clearInterval(this.data.timer);
|
||||
console.log('show-----');
|
||||
this.setDateMsg();
|
||||
this.data.timer = setInterval(() => {
|
||||
this.setDateMsg();
|
||||
}, 1000);
|
||||
},
|
||||
hide() {
|
||||
console.log('hide-----');
|
||||
clearInterval(this.data.timer);
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* 组件的初始数据
|
||||
*/
|
||||
data: {
|
||||
timer: null as any,
|
||||
date: '',
|
||||
week: '',
|
||||
weekArr: ['日', '一', '二', '三', '四', '五', '六'],
|
||||
},
|
||||
|
||||
/**
|
||||
* 组件的方法列表
|
||||
*/
|
||||
methods: {
|
||||
setDateMsg() {
|
||||
console.log('ddd');
|
||||
this.setData({
|
||||
date: formatTime(new Date()),
|
||||
week: `星期${this.data.weekArr[new Date().getDay()]}`,
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user