Vue.js高效前端开发(时钟制作)

效果图

HTML5代码

html 复制代码
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		
		<title>Web时钟</title>
	<style>
		#app{
			text-align: center;padding: 50px;
		}
		.banner{
			width: 800px;
			height: 150px;
			line-height: 150px;
			text-align: center;
			box-shadow: 5px 5px 10px #888888;
			font-size: 40px;
			font-weight: bolder;
			background-color: #033592;
			color: #FFF;
			margin: 0px auto;
			border-radius: 20px;
		}
		
	</style>
	</head>
	<body>
		<div id="app">
			<div class="banner">
				当前日期时间:{{ date | formatDate }};
			</div>
		</div>
		<script src="js/vue.js"></script>
		<script>
			var padDate=function(val){
				return val<10?"0"+val:val;
			};
			var vm=new Vue({
				el:"#app",
				data:{
					date:null
				},
				created:function(){
					this.date=new Date();
				},
				mounted:function(){
					var _this=this;
					this.timer=setInterval(function(){
						_this.date=new Date();}
						,1000);
					},
					beforeDestroy:function(){
						if(this.timer){
							clearInterval(this.timer);
						}
					},
					filters:{
						formatDate:function(val){
							var currdate =new Date();
							var year=currdate.getFullYear();
							var month=padDate(currdate.getMonth()+1);
							var day =padDate(currdate.getDate());
							var hours=padDate(currdate.getHours());
							var minutes=padDate(currdate.getMinutes());
							var seconds=padDate(currdate.getSeconds());
							return year+"-"+month+"-"+day+""+hours+":"+minutes+":"+seconds;
							
							
							
						}
					}
			});
			
			
			
			
		</script>
	</body>
</html>

vue.js文件自行下载

相关推荐
不羁的fang少年41 分钟前
前端常见问题(vue,css,html,js等)
前端·javascript·css
change_fate1 小时前
el-menu折叠后文字下移
前端·javascript·vue.js
yivifu1 小时前
CSS Grid 布局详解(2025最新标准)
前端·css
o***Z4482 小时前
前端性能优化案例
前端
张拭心2 小时前
前端没有实际的必要了?结合今年工作内容,谈谈我的看法
前端·ai编程
姜太小白3 小时前
【前端】CSS媒体查询响应式设计详解:@media (max-width: 600px) {……}
前端·css·媒体
weixin_411191843 小时前
flutter中WebView的使用及JavaScript桥接的问题记录
javascript·flutter
HIT_Weston3 小时前
39、【Ubuntu】【远程开发】拉出内网 Web 服务:构建静态网页(二)
linux·前端·ubuntu
百***06013 小时前
SpringMVC 请求参数接收
前端·javascript·算法
天外天-亮3 小时前
Vue + excel下载 + 水印
前端·vue.js·excel