問題:new Date()在安卓下正常,在IOS下顯示不出來。
原因:在IOS下,new Date(“2000-2-22 00:10”),返回的是undefined,因為IOS不支持這種類型格式。
解決:更換下格式:new Date(“2000/2/22”) 可以正常顯示。
如果說確實要用到 new Date(“2000-2-22 00:10”) 這種格式的數據,那么我們可以借助 date-fns
的JS庫
npm install date-fns
import { parse } from 'date-fns'async goUseCardCoupon(item) {// 這里存在new Date()在IOS不生效的bug,因而用到date-fns庫const currentTime = new Date()const startTime = parse(item.start_time, 'yyyy-MM-dd HH:mm:ss', new Date())if (startTime > currentTime) {this.$toast.fail('該卡券暫未生效,請在有效使用時間內使用')return}
}