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

相关推荐
hj5914_前端新手2 小时前
javascript基础- 函数中 this 指向、call、apply、bind
前端·javascript
薛定谔的算法2 小时前
低代码编辑器项目设计与实现:以JSON为核心的数据驱动架构
前端·react.js·前端框架
Hilaku2 小时前
都2025年了,我们还有必要为了兼容性,去写那么多polyfill吗?
前端·javascript·css
yangcode2 小时前
iOS 苹果内购 Storekit 2
前端
LuckySusu2 小时前
【js篇】JavaScript 原型修改 vs 重写:深入理解 constructor的指向问题
前端·javascript
LuckySusu2 小时前
【js篇】如何准确获取对象自身的属性?hasOwnProperty深度解析
前端·javascript
LuckySusu2 小时前
【js篇】深入理解 JavaScript 作用域与作用域链
前端·javascript
LuckySusu2 小时前
【js篇】call() 与 apply()深度对比
前端·javascript
LuckySusu2 小时前
【js篇】addEventListener()方法的参数和使用
前端·javascript
该用户已不存在2 小时前
6个值得收藏的.NET ORM 框架
前端·后端·.net