簡體   English   中英

vuejs如何在后台運行方法

[英]How to run a method in the background in vuejs

我有如下登錄表單。 工人可以輕松地首次登錄和注銷。 當工作人員注銷並立即嘗試再次登錄並且我得到錯誤漂移未定義時,問題就出現了。 我想在代碼的漂移部分添加延遲,但我不希望工作人員等待延遲再次被記錄。

所以像 10 秒或更長時間的延遲,但工作人員不應該等待登錄。 繼續在后台檢查漂移並運行漂移部分,但它不應該凍結登錄。 幫我實現這個

<template>
  <v-layout row wrap>
    <v-flex xs12 md7 lg8 >
        <v-layout row wrap>
          <v-flex md12 lg12>
            <div>
              <v-form :model='worker' ref='loginForm'>
                <v-layout row wrap>
                  <v-flex xs12 md6>
                    <v-text-field
                      label='Email Address'
                      v-model='worker.email'
                      name="email"
                      :rules='emailRules'
                      required>
                    </v-text-field>
                  </v-flex>
                  <v-flex xs12 md6>
                    <v-text-field
                      label='Password'
                      v-model='worker.password'
                      name="password"
                      type='password'
                      :rules='passwordRules'
                      required>
                    </v-text-field>
                  </v-flex>
              </v-layout>
                <v-btn @click='login'>Log In</v-btn>
              </v-form>
            </div>
          </v-flex>
        </v-layout>
    </v-flex>
  </v-layout>
</template>

<script>
export default {
  data: function() {
    return {
      worker: {
        email: '',
        password: ''
      },
      error: '',
      emailRules: [
        value => !!value || 'Please enter your email address',
      ],
      passwordRules: [
        value => !!value || 'Please enter a password'
      ]
    };
  },
  methods: {
    login() {
      var that = this;

      if (this.$refs.loginForm.validate()) {
        this.$axios.post('sign_in.json', { user: this.worker }).then(function(response) {
          drift.identify(response.data.worker.id, {
            email: response.data.worker.email
          })
          window.location.href = '/my_account';
        }).catch(function(error) {
          that.error = error;
        });
      }
    }
  }
};
</script>

我不熟悉聊天框/漂移,所以我不知道你是如何獲得“漂移”實例的,但我認為你將不得不為“漂移”的可用性添加某種異步檢查例如,像

   login() {
          var that = this;
    
          if (this.$refs.loginForm.validate()) {
            this.$axios.post('sign_in.json', { user: this.worker }).then(async function(response) {
              await getDrift().identify(response.data.worker.id, {
                email: response.data.worker.email
              })
              window.location.href = '/my_account';
            }).catch(function(error) {
              that.error = error;
            });
          }
     

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM