在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/HTML/ Vue點(diǎn)擊登錄的時(shí)候自動(dòng)加了問(wèn)號(hào)?

Vue點(diǎn)擊登錄的時(shí)候自動(dòng)加了問(wèn)號(hào)?

  1. 最近在用Vue來(lái)做登錄頁(yè)面, 當(dāng)輸入賬號(hào)和密碼之后, 點(diǎn)擊登錄刷新了一下, 莫名的在我路徑后面多加了一個(gè)問(wèn)號(hào), 我在代碼里打印沒(méi)有打印出來(lái), 但是當(dāng)我第二次點(diǎn)擊的時(shí)候才打印出來(lái), 在打印后面給了路由跳轉(zhuǎn), 最后到路由跳轉(zhuǎn)卻執(zhí)行不了?, 其次用debugger來(lái)做調(diào)試的, 我當(dāng)前的判斷竟然沒(méi)有進(jìn)去, 很奇怪, 判斷可以打印, 用debugger調(diào)試沒(méi)有執(zhí)行

html

    <div class="login_form">
      <el-form :label-position="labelPosition" label-width="80px" :model="form">
        <el-form-item>
          <i class="account_icon"></i>
          <el-input v-model="form.userName" placeholder="登錄賬戶" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <i class="password_icon"></i>
          <el-input type="password" v-model="form.password" auto-complete="off" placeholder="登錄密碼"></el-input>
        </el-form-item>
        <div class="checkbox">
          <input type="checkbox">
          <span class="login_password">記住密碼</span>
        </div>
        <div>
          <button @click="onSubmit" :plain="true">登錄</button>
        </div>
        <div class="login_embellish">
          <i class="embellish_one"></i>
        </div>
      </el-form>
      <i class="modifier_left"></i>
      <i class="modifier_right"></i>
    </div>

js

  export default {
    data() {
      return {
        labelPosition: "right",
        form: {
          userName: "admin",
          password: "admin123"
        },
      };
    },
    methods: {
      // 提交
      onSubmit() {
        let paramsData = {
          username: this.form.userName,
          password: this.form.password
        };
        debugger
        this.$ajax.post(this.$api.Login, paramsData).then(res => {
            if (res.data.status == 200) {
              console.log("res", res);
              let params = "";
              localStorage.params = JSON.stringify(res.data.data);
              localStorage.setItem("params",localStorage.params);
              this.$router.push({ path: "/index" })
            }else if(res.data.status == 401) {
              this.$message.error(res.data.message);
            }
          })
          .catch(err => {
            console.log(err);
          })
      }
    }
  }
  1. 第一點(diǎn)擊登錄, 刷新了一下, 路徑后面多加一個(gè)問(wèn)號(hào)

clipboard.png

  1. 第二次點(diǎn)擊登錄, 才打印出來(lái)

clipboard.png

4.用debugger調(diào)試, 判斷沒(méi)有進(jìn)來(lái)

clipboard.png

回答
編輯回答
枕頭人

你用了 form 表單。 然你的 input 都沒(méi)有name屬性。 你應(yīng)該在 onSubmit 時(shí) 阻止下冒泡或默認(rèn)事件 就可以了。 或者 把 el-form 組件去掉。 因?yàn)橐矝](méi)什么必要,加了form 無(wú)非就是 在兩個(gè)input 中按回車能自動(dòng)提交。
就這樣

2018年9月8日 05:48
編輯回答
悶油瓶

我也出現(xiàn)url中加問(wèn)號(hào)的情況,原因就是上面評(píng)論中說(shuō)的form表單的提交事件。
我的解決方案是使用了click.prevent阻止默認(rèn)事件,就好了。
<button @click.prevent="onSubmit" :plain="true">登錄</button>

2017年4月6日 17:35