[Vuejs]-How to get data from server before component is mounted vue2.0

0👍

resolved with:

checkLogged: function() {
        return new Promise((resolve,reject) => {
          this.$http.get('xxx').then(response => {
            if (response.body == 1) {
              resolve(true);
            } else {
              resolve(false);
            }
          }, response => {
            reject('connection failure');
          });
        });
    },

and in 2nd file:

this.$root.checkLogged().then((response) => {
            if(response){
                this.logged = true
            }else{
                router.push("/")
            }
        })
👤Proxr

Leave a comment