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>
相关推荐
大叔_爱编程36 分钟前
基于用户评论的热点问题挖掘与反馈分析系统-django+spider+uniapp
python·django·uni-app·毕业设计·源码·课程设计·spider
源码潇潇和逸逸15 小时前
独立部署高校圈子平台:PHP+UniApp打造社交+交易+服务一站式校园解决方案
开发语言·uni-app·php
2501_9160088918 小时前
2026 iOS 证书管理,告别钥匙串依赖,构建可复制的签名环境
android·ios·小程序·https·uni-app·iphone·webview
2501_915918411 天前
iOS App 拿不到数据怎么办?数据解密导出到分析结构方法
android·macos·ios·小程序·uni-app·cocoa·iphone
2501_916008891 天前
iOS App 抓包看不到内容,从有请求没数据一步步排查
android·ios·小程序·https·uni-app·iphone·webview
扶苏10021 天前
记一次 uni-app开发微信小程序 textarea 的“伪遮挡”踩坑实录
微信小程序·小程序·uni-app
RuoyiOffice2 天前
企业请假销假系统设计实战:一张表、一套流程、两段生命周期——BPM节点驱动的表单变形术
java·spring·uni-app·vue·产品运营·ruoyi·anti-design-vue
KongHen022 天前
uniapp-x实现自定义tabbar
前端·javascript·uni-app·unix
RuoyiOffice2 天前
SpringBoot+Vue3+Uniapp实现PC+APP双端考勤打卡设计:GPS围栏/内网双模打卡、节假日方案、定时预生成——附数据结构和核心源码讲解
java·spring·小程序·uni-app·vue·产品运营·ruoyi
2501_915921432 天前
2026 iOS 上架新趋势 iOS 发布流程模块化
android·ios·小程序·https·uni-app·iphone·webview