Vue之過濾器詳解
阿新 • • 發佈:2021-11-22
<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> .config.productionTip = false; //全域性過濾器 Vue.filter('mySlice',function(value) { return value.slice(0,4) }) new Vue({ el: "#root",data: { time: 1637047951556 //時間戳 },computed: { fmtwww.cppcns.comTime() { rhttp://www.cppcns.cometurn day(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>
總結
本篇文章就到這裡了,希望能夠給你帶來幫助,也希望您能夠多多關注我們的更多內容!