Meteor Spacebars {{#if someCondition}} shows data briefly on page refresh

前端 未结 3 1205
独厮守ぢ
独厮守ぢ 2021-01-24 18:16

I have tried this a couple different ways and they both behave the same way (see below for code). I\'m using a spacebars if condition (and tried using a helper as well) to check

3条回答
  •  情书的邮戳
    2021-01-24 18:54

    You need to subscribe to Meteor.users collection, template will be rendered after Meteor.user() is created, if you won't wait for subscription page will blink because at start there is nothing in Meteor.users collection.

    You can use new Meteor functionality on template where you have login field

    Template.login.onCreated(function () {
      var self = this;
    
      self.autorun(function () {
        self.subscribe("users");
      });
    });
    

    And in HTML

    {{#if Template.subscriptionsReady}}
        
    {{else}}
        Give me a second...
    {{/if}}
    

    Of course you need to create publish named 'users'

提交回复
热议问题