我的主选项卡(全部)工作正常,但是当我转到div加载内容的第二个选项卡时,diffForHumans()将不再起作用。这是我模型中的代码:
let momentDate = moment('2018-01-01', 'YYYY-MM-DD');
// I need to create a full clone of moment here
// Tried:
// -- let copy = {...moment}
// -- let copy = new(moment)
// -- let copy = clone(moment) // https://www.npmjs.com/package/clone
// -- let copy = Object.assign({}, moment)
let momentCopy = /*new*/ moment;
momentCopy.fn.xFormat = function() {
return this.format('[new-format-fn::]' + 'YYYY-MM-DD')
}
// expected Error:momentDate.xFormat is not a function
// but xFormat applied to momentDate
log(momentDate.xFormat());
log(momentCopy().xFormat())
这是来自我的home.blade.php:
protected $dates = ['schedule'];
这是来自我的dota.blade.php
<div class="time">
@if($match->status == 'ongoing')
<span style="color: #72A326; text-shadow: 1px 1px 0px #4A7010; font-weight: bold; font-size: 16px"> LIVE</span>
@elseif($match->status == 'settled')
{{$match->schedule->diffForHumans()}} <span style="color: #606060; font-weight: bold; font-size: 16px"> SETTLED</span>
@elseif($match->status == 'draw')
{{$match->schedule->diffForHumans()}} <span style="color: #606060; font-weight: bold; font-size: 16px"> DRAW - CREDITS RETURNED</span>
@else
<strong class="match_countdown" data-schedule="{{$match->schedule}}">{{$match->schedule->diffForHumans()}}</strong>
@endif
</div>
这是脚本:
<div class="time">
@if($match->status == 'ongoing')
<span style="color: #72A326; text-shadow: 1px 1px 0px #4A7010; font-weight: bold; font-size: 16px"> LIVE</span>
@elseif($match->status == 'settled')
{{$match->schedule->diffForHumans()}} <span style="color: #606060; font-weight: bold; font-size: 16px"> SETTLED</span>
@elseif($match->status == 'draw')
{{$match->schedule->diffForHumans()}} <span style="color: #606060; font-weight: bold; font-size: 16px"> DRAW - CREDITS RETURNED</span>
@else
<strong class="match_countdown" data-schedule="{{$match->schedule}}">{{ \Carbon\Carbon::parse($match->schedule)->diffForHumans() }}</strong>
@endif
</div>
因此,基本上没有任何区别。从我的家庭刀片选项卡上,它们也都具有相同的脚本,也可以正常工作,在我的家中,从现在开始显示3天2时46秒,并且当计划时间为0时,它将切换为状态“比赛即将开始”所以现在,在我的dota标签上,它的工作方式不同。有什么想法吗?