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

相关推荐
chilavert3181 小时前
技术演进中的开发沉思-191 JavaScript: 发展历程(上篇)
开发语言·javascript·ecmascript
努力的小郑1 小时前
今晚Cloudflare一哆嗦,我的加班计划全泡汤
前端·后端·程序员
武昌库里写JAVA2 小时前
微擎服务器配置要求,微擎云主机多少钱一年?
java·vue.js·spring boot·后端·sql
dy17172 小时前
el-table表头上下显示内容
javascript·vue.js·elementui
q***64972 小时前
头歌答案--爬虫实战
java·前端·爬虫
凌波粒2 小时前
SpringMVC基础教程(4)--Ajax/拦截器/文件上传和下载
java·前端·spring·ajax
亮子AI3 小时前
给你的应用加上Google账号登录
javascript
液态不合群3 小时前
DDD驱动低代码开发:从业务流程到领域模型的全链路设计
前端·低代码·架构·ddd
jonyleek3 小时前
JVS低代码开发中,如何创建自定义前端页面并接入到现有系统中,从创建到接入的全攻略
前端·低代码·前端框架·软件开发
努力往上爬de蜗牛3 小时前
react native 实现选择图片或者拍照上传(多张)
javascript·react native·react.js