生活随笔
收集整理的這篇文章主要介紹了
helper的使用
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
helper的使用
在文件app下創(chuàng)建文件夾extend,在這里創(chuàng)建你所要使用的工具
在本次項(xiàng)目中創(chuàng)建了一個(gè)時(shí)間格式的文件
helper.ts文件module.exports = {changeDateTime(time,type) {var date = new Date(time);var month = this.addZore(date.getMonth() + 1);var mint = this.addZore(date.getHours()) + ':' + this.addZore(date.getMinutes()) + ':' + this.addZore(date.getSeconds());var dateStr = type=='str'?(date.getFullYear() + '年' + month + '月' + this.addZore(date.getDate())) + '日':type=='date'?(date.getFullYear() + '-' + month + '-' + this.addZore(date.getDate())):type=='min'?(date.getFullYear() + '-' + month + '-' + this.addZore(date.getDate())+ ' ' + mint):(date.getFullYear() + '-' + month + '-' + this.addZore(date.getDate()))return dateStr},addZore(value) {return ("0" + value).slice(-2);}
}
在模板渲染頁面中的使用
<p class="list-font"> <span>{{helper.changeDateTime(items.post_date,'min')}}</span></p>
這樣就是完成一個(gè)時(shí)間格式化的工具
總結(jié)
以上是生活随笔為你收集整理的helper的使用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。