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

相关推荐
枷锁—sha1 分钟前
【DVWA系列】——CSRF——Medium详细教程
android·服务器·前端·web安全·网络安全·csrf
枷锁—sha2 分钟前
跨站请求伪造漏洞(CSRF)详解
运维·服务器·前端·web安全·网络安全·csrf
群联云防护小杜18 分钟前
深度隐匿源IP:高防+群联AI云防护防绕过实战
运维·服务器·前端·网络·人工智能·网络协议·tcp/ip
DanB2431 分钟前
html复习
javascript·microsoft·html
汉得数字平台36 分钟前
【鲲苍提效】全面洞察用户体验,助力打造高性能前端应用
前端·前端监控
花海如潮淹43 分钟前
前端性能追踪工具:用户体验的毫秒战争
前端·笔记·ux
_丿丨丨_6 小时前
XSS(跨站脚本攻击)
前端·网络·xss
天天进步20156 小时前
前端安全指南:防御XSS与CSRF攻击
前端·安全·xss
呼啦啦呼啦啦啦啦啦啦7 小时前
利用pdfjs实现的pdf预览简单demo(包含翻页功能)
android·javascript·pdf
拾光拾趣录8 小时前
括号生成算法
前端·算法