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>
相关推荐
前端Hardy2 天前
用 uni-app x 重构我们的 App:一套代码跑通 iOS、Android、鸿蒙!人力成本直降 60%
前端·ios·uni-app
嘉琪0013 天前
uni-app 核心坑点及解决方案——2026 0309
uni-app
行者-全栈开发3 天前
uni-app 审批流程组件封装:打造企业级工作流可视化方案
uni-app
2501_916008893 天前
iPhone 上怎么抓 App 的网络请求,在 iOS 设备上捕获网络请求
android·网络·ios·小程序·uni-app·iphone·webview
jingling5553 天前
无需重新安装APK | uni-app 热更新技术实战
前端·javascript·前端框架·uni-app·node.js
遇见小美好y3 天前
uniapp 实现向下追加数据功能
前端·javascript·uni-app
行者-全栈开发3 天前
43 篇系统实战:uni-app 从入门到架构师成长之路
前端·typescript·uni-app·vue3·最佳实践·企业级架构
00后程序员张3 天前
iOS上架工具,AppUploader(开心上架)用于证书生成、描述文件管理Xcode用于应用构建
android·macos·ios·小程序·uni-app·iphone·xcode
万物得其道者成3 天前
uniapp 滑动过快 onReachBottom 事件不触发
uni-app