<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>过滤器</title>
</head>
<script type="text/javascript" class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="js/vue.js" ></script>
<script>
Vue.filter('date',data=>{
let date = new Date(data);
return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()+' '+date.getHours()+':'+date.getMinutes()+':'+date.getSeconds();
})
window.onload = function(){
//配置是否允许检查代码,方便调试,生产环境中设置为false
Vue.config.devtools = true; //检查代码
Vue.config.productioinTip = false; //有强迫症的,可以关掉生产中的提示信息
let vm = new Vue({
el: "#div1",
data:{
currentTime: Date.now()
},
filters:{
time: data=>{
let date = new Date(data);
return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()+' '+date.getHours()+':'+date.getMinutes()+':'+date.getSeconds();
}
}
});
}
</script>
<body>
<div id="div1">
<h1>{{currentTime | time}}</h1>
</div>
</body>
</html>
共同学习,写下你的评论
评论加载中...
作者其他优质文章