vuejs / Discussion

Vue.js discussion
167 stars 17 forks source link

How can I set a component as invisible by default, then change its display status after the judgement function is executed ? #315

Open yxzhan opened 9 years ago

yxzhan commented 9 years ago

I got a 'time-divider' component, its display status is depend on whether its release time is equal to the release time of the latest message.

But my judgement function (v-if="showTimeDivider(this)") should that some time to execute, cause the component flash up and disappear(when the result is false)

The flow is: Component ready(visible) -> judgement function executing -> return false, hide component

<!-- time-divider -->
<template  v-if="showTimeDivider(this)" v-cloak>
       <div class="cross-line green">
               <div class="day-time">{{time | messageDay}}</div>
        </div>
</template>

showTimeDivider: function(item){
            if(item.$index > 0){
                var fTime = item.time || '';
                var sTime = this.timeline[item.$index - 1].time || '';

                var t1 = fTime.split(' ');
                var t2 = sTime.split(' ');

                return (t1[0] !== t2[0]);
            }
            return true;
}
swift1 commented 9 years ago
<template id="..." v-if="show"> 
data: function(){
    return {
        show: false
    }
},
ready: {
    this.showTimeDivider(some_item);
},
methods: {
    showTimeDivider: function(item){
        if(...)
            this.show = true;
    )
}