sometime need force update, eg: use filter with moment.formNow() format time
See original GitHub issueI have not find the optimal way do it.
It’s my solution now:
filter
Vue.filter('fromNow',function(v){
return moment(v).fromNow()
})
data.alarms
function generateData() {
var re = []
_.forEach(_.range(10), function (v) {
re.push({name: '滨江西路30' + v, time: new Date(Date.now() - v * 1000*30), flag: v % 2 == 0 ? 1 : 2})
})
return re;
}
force update
ready(){
var ts=this,flag=true;
ts.$intervalTime=setInterval(function(){
_.forEach(ts.alarms,function(v){
v.time= moment(v.time).add(flag?-1:1,'ms')
})
flag=!!flag
},30*1000)
},
destroy(){
if(this.$intervalTime)clearInterval(this.$intervalTime)
}
It’s so bad implementation
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
javascript - How to format time since xxx e.g. “4 minutes ago ...
Good function, but some remarks. Changed the first line to: var seconds = Math.floor(((new Date().getTime()/1000) - date)) to work with unix timestamps.
Read more >Time from now - momentjs.com
Range Key Sample Output
0 to 44 seconds s a few seconds ago
unset ss 44 seconds ago
45 to 89 seconds m a minute ago...
Read more >Docs - Moment.js
We will release data updates for Moment-Timezone following IANA time zone database ... var moment = require('moment'); // require moment().format();.
Read more >Moment.js vs date-fns: How to spot slow loading scripts and fix ...
This change alone increased the filtering time of this data from around 6 seconds to 600 milliseconds. Why I decided to test for...
Read more >Update Your Date Filters Automatically - The Flerlage Twins
We have a dashboard with a date filter (usually a slider) at the top to allow ... You can use () for the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Please ask these questions on forum or Gitter.
You could use a directive, instead of filter. Check my gist here: https://gist.github.com/pespantelis/cdf42a52e5bb8ee095a08abdb58c8edf
Hope it helps!