Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在nuxt中提交表单时,为什么登录页面重定向到索引页面?_Javascript_Html_Vue.js_Authentication_Nuxt.js - Fatal编程技术网

Javascript 在nuxt中提交表单时,为什么登录页面重定向到索引页面?

Javascript 在nuxt中提交表单时,为什么登录页面重定向到索引页面?,javascript,html,vue.js,authentication,nuxt.js,Javascript,Html,Vue.js,Authentication,Nuxt.js,我正在尝试使用nuxt和nuxt/auth模块创建一个正常的登录页面。 i hapening是指当单击submit按钮时,指向索引页的一个链接正在hapening。 这是我的html代码: <template> <div class="container"> <b-card header="Sign In" header-bg-variant="secondary" header-text-variant="white"

我正在尝试使用nuxt和nuxt/auth模块创建一个正常的登录页面。 i hapening是指当单击submit按钮时,指向索引页的一个链接正在hapening。 这是我的html代码:

<template>
  <div class="container">
    <b-card
     header="Sign In"
     header-bg-variant="secondary"
     header-text-variant="white"
     style="width: 20rem;"
   >
     <b-form @submit="onSubmit">
      <b-form-group
        id="input-group-1"
        label="Username:"
        label-for="input-1"
      >
       <b-form-input
        id="input-1"
        v-model="form.userName"
        type="email"
        required
        placeholder=""
      ></b-form-input>
       </b-form-group>

       <b-form-group id="input-group-2" label="Password:" label-for="input-2">
         <b-form-input
           id="input-2"
           type="password"
           required
           v-model="form.password"
           placeholder=""
         ></b-form-input>
       </b-form-group>

       <b-form-group id="input-group-3" label="Reference:" label-for="input-3">
        <b-form-input
        id="input-3"
        v-model="form.reference"
        required
        placeholder=""
      ></b-form-input>
      </b-form-group>
      <b-button type="submit" variant="primary">Submit</b-button>
  </b-form>
  </b-card>
 </div>
 </template>
我试图在html中像这样放置protect事件
@submit.stop.protect=“onSubmit”
,但也没有。 我想要的是,如果登录完成,则转到mediapalyer页面;如果登录未完成,则只需执行err控制台

async onSubmit(evt) {
    evt.preventDefault();
    var self = this;
    var data = {
      email: self.form.userName,
      password: self.form.password,
      role: "publisher"
    };

    try{
      await this.$auth.loginWith("local", {
        data: data
      })
    }catch (e) {
      console.log(e);
      self.emailCheck = true;
    }

    if (this.$auth.loggedIn) {
      axios.defaults.headers.common["authorization"] = self.$auth.getToken(
        "local"
      )
      axios.get(self.baseUrl + "devices/config/" + self.form.reference)
        .then(async function (response) {

          self.$router.push({
            name: "mediaPlayer"
          });

        })
        .catch(function (error) {
          console.log(error);
          self.refCheck = true;
        });
      }
    }