uniapp【组件封装】时间戳格式化为星期

组件

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>
相关推荐
2501_9159184126 分钟前
iOS App性能测试工具的实现方法与优化循环指南
android·ios·小程序·https·uni-app·iphone·webview
斯内普吖2 小时前
(开源)高校素拓分管理系统小程序实战指南 基于 Java + SpringBoot + uni-app + Vue + MySQL
java·spring boot·mysql·小程序·uni-app·开源
海阔天空66883 小时前
uniapp开启调试模式
uni-app·uniapp开启调试模式
anyup21 小时前
分享 5 套 uni-app 实用主题,一键适配暗黑模式
前端·uni-app·视觉设计
gg159357284601 天前
Uni-app跨平台开发全解课程:从零基础到企业级多端落地实战
vue.js·uni-app
xshirleyl2 天前
uniapp小兔鲜儿day3
uni-app
Geek_Vison3 天前
2026 跨端框架横评:FinClip、Taro、uni-app、Remax、mPaaS 五款工具技术+业务双维度测评
小程序·uni-app·taro·mpaas·小程序容器
RuoyiOffice3 天前
从 0 到 1 搭建 RuoyiOffice:30 分钟跑通后端+前端+移动端
前端·spring boot·uni-app·开源·oa·ruoyioffice·hrm
Geek_Vison3 天前
APP集成了50多个小程序后,如何搭建一个小程序管理平台来管理这些小程序~
小程序·uni-app·apache·mpaas·小程序容器
梦曦i4 天前
uni-router v1.1.1发布:守卫超时保护+路由监听
前端·uni-app