question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sometime need force update, eg: use filter with moment.formNow() format time

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
phanancommented, Jun 15, 2016

Please ask these questions on forum or Gitter.

1reaction
pespanteliscommented, Jun 15, 2016

You could use a directive, instead of filter. Check my gist here: https://gist.github.com/pespantelis/cdf42a52e5bb8ee095a08abdb58c8edf

Hope it helps!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found