<!DOCTYPE html>
<html lang="en">
<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>Document</title>
</head>
<body>
<div id="app">
<p>{{msg1 | dateFormat}}</p>
</div>
<div id="app1">
<p>{{msg2 | dateFormat2}}</p>
</div>
<script src="./js/vue.js"></script>
<script>
function dategetTwo(date) {
return date < 10 ? '0' + date : date;
}
// 整理日期
// Vue.filter('dateformat',function(data,arg0){
// return data.getFullYear()+"-"+dategetTwo((data.getMonth()+1))+"-"+dategetTwo(data.getDate());
// })
Vue.filter('dateformat', function (data, arg0) {
var y = data.getFullYear().toString().padStart(2, '0');
var m = (data.getMonth() + 1).toString().padStart(2, '0');
var d = data.getDate().toString().padStart(2, '0');
// return y +'-'+m+'-'+d;
// return `${dategetTwo(y)}-${dategetTwo(m)}-${dategetTwo(d)}`
return `${y}-${m}-${d}`
})
var vm = new Vue({
el: "#app",
data: {
msg1: new Date(),
},
})
var vm2 = new Vue({
el: "#app1",
data: {
msg2: new Date(),
},
methods: {},
// 私有过滤器,只对某个vue实例起作用
filters: {
dateFormat2: function (data, arg0) {
var y = data.getFullYear().toString().padStart(2, "0");
var m = (data.getMonth() + 1).toString().padStart(2, "0");
var d = data.getDate().toString().padStart(2, "0");
return `你好${y}-${m}-${d}`;
}
}
})
</script>
</body>
</html>
网友评论