组件
components/dos-week.vue
html
<template>
<text>{{week}}</text>
</template>
<script>
export default {
props: {
'time': String
},
mounted(e) {
this.week = this.getWeek(Number(this.time))
},
data() {
return {
week: ''
}
},
methods: {
// 通过时间戳计算星期,如 getWeek(1706190315813),得到 周三
getWeek(strDate, type) {
let index = new Date(strDate).getDay();
let weekList = []
if (type === '星期') {
weekList = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
} else {
weekList = ["周天", "周一", "周二", "周三", "周四", "周五", "周六"];
}
return weekList[index];
}
}
}
</script>
使用
js
import DOS_week from './components/dos-week.vue'
js
components: {
DOS_week
},
html
<DOS_week :time='item.time'></DOS_week>