V
V
Vladimir Banduristov2018-05-28 15:14:43
Vue.js
Vladimir Banduristov, 2018-05-28 15:14:43

How to make the authorization form stop blinking?

I am creating a simple Vue.js application. There is a component like this

<div id="app">
  <template v-if="auth === true">
    ТУТ ОСНОВНОЙ КОНТЕНТ
  </template>
  <template v-else>
    ФОРМА АВТОРИЗАЦИИ
  </template>
</div>

<script>
  ...
  data: function () {
      return {
          auth: false
      }
  },
  created() {
        this.checkUser();
    },
    methods: {
    	checkUser: function () {
    		...
    		Тут проверка пользователя на авторизацию и в случае успеха:
    		this.auth = true;
    		...
    	}
    }
    ...
</script>

Everything works fine and smoothly, but the problem is that when the page is reloaded, an authorization form still appears for a split second, the question is how to get rid of this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2018-05-28
@vtboren

Add a third state, it is also default - uncertainty, it is not clear whether the user is authorized or not:

data: () => ({
  auth: null,
}),
methods: {
  checkUser() {
    ...
    // указываем false только в случае отрицательного результата проверки
    this.auth = false;
    ...
  },
},

<template v-else-if="auth === false">
  ФОРМА АВТОРИЗАЦИИ
</template>

L
lavezzi1, 2018-05-28
@lavezzi1

https://ru.vuejs.org/v2/api/index.html#v-cloak

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question