过滤器时间的格式化输出:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app">
{
{date|timeFormat}}
</div>
</body>
</html>
<script src="./js/vue.js"></script>
<script>
Vue.filter("timeFormat",function(val){
var date=new Date(val)
var Y=date.getFullYear();
var m=date.getMonth()+1;
var d=date.getDate();
var H=date.getHours()
var mm=date.getMinutes()+"";
mm=mm.padStart(2,0)
var s=date.getSeconds()+""
s=s.padStart(2,0)
return `${
Y}/${
m}/${
d} ${
H}:${
mm}:${
s}`;
})
var vm=new Vue({
el:"#app",
data:{
date:new Date()
}
})
</script>