VUE时间戳转换,src引入的方式
1.通过vue过滤器---在创建 Vue 实例之前全局定义过滤器vue.filter
index.html
<div id="app">
<div>{
{time | timeStamp}}</div>
</div>
<script src="../static/vue.js"></script>
<script src="../static/style.js"></script>
<script>
var VM = new Vue({
el:"#app",
data:{
time:"1591843492"
}
})
</script>
style.js
Vue.filter('timeStamp', function (value) {
if (!value) return '---'
//时间戳转换
var date = new Date(value * 1000);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
Y = date.getFullYear() + '-';
M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) :