0
点赞
收藏
分享

微信扫一扫

【Vue2.0】—过滤器(七)

【Vue2.0】—过滤器(七)

【Vue2.0】—过滤器(七)_显示格式

<body>
<div id="root">
<h2>显示格式化后的时间</h2>
<!-- 计算属性实现 -->
<h2>现在是{{fmtTime}}</h2>
<!-- methods实现 -->
<h2>现在是{{getFmtTime()}}</h2>
<!-- 过滤器时间实现-->
<h2>现在是{{time | timeFormater}}</h2>
</div>

<div id="root2">
<h2>现在是:{{msg |mySlice }}</h2>
</div>
<script>
Vue.config.productionTip = false;
//全局过滤器
Vue.filter('mySlice', function(value) {
return value.slice(0, 4)
})
new Vue({
el: "#root",
data: {
time: 1637047951556 //时间戳
},
computed: {
fmtTime() {
return dayjs(this.time).format('YYYY年MM月DD HH:mm:ss')
}
},
methods: {
getFmtTime() {
return dayjs(this.time).format('YYYY年MM月DD HH:mm:ss')
}
},
filters: {
timeFormater(value) {
return dayjs(value).format('YYYY年MM月DD HH: mm: ss ')
}
},

})


new Vue({
el: "#root2",
data: {
msg: 'hello world'
}
})
</script>
</body>

【Vue2.0】—过滤器(七)_vue.js_02


举报

相关推荐

vue过滤器

Vue过滤器filter

Vue 的过滤器

【VUE】过滤器Filter

vue filter 过滤器

vue2-过滤器

0 条评论