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文件自行下载

相关推荐
中微子1 小时前
JavaScript事件循环机制:面试官最爱问的10个问题详解
前端
Eighteen Z1 小时前
CSS揭秘:10.平行四边形
前端·css·css3
拾光拾趣录1 小时前
虚拟DOM
前端·vue.js·dom
爱学习的茄子1 小时前
JavaScript事件循环深度解析:理解异步执行的本质
前端·javascript·面试
1024小神1 小时前
cocos游戏开发中多角色碰撞,物理反弹后改变方向的实现逻辑
前端·javascript
ruanhongbiao1 小时前
饿了么el-upload上传组件报错:TypeError: ***.upload.addEventListener is not a function
javascript·elementui
_一两风1 小时前
JS执行机制-event loop
javascript
止观止1 小时前
JavaScript对象创建9大核心技术解析
开发语言·javascript·ecmascript
摆烂为不摆烂1 小时前
😁深入JS(五): 一文让你完全理解 hash 与 history 路由,手写前端路由
前端
1024小神1 小时前
cocos游戏开发中,如何制作一个空气墙
前端·javascript