Does Vue automatically add a question mark when you click to log in?

  1. recently used Vue as the login page. After entering the account number and password, I clicked on the login to refresh it. Inexplicably, I added an extra question mark at the back of my path. I printed it but did not print it out in the code, but it was printed out when I clicked the second time. After printing, I gave the route jump, and finally the route jump could not be performed. Secondly, I used debugger to debug. My current judgment didn"t go in. It"s strange that it can print and debug with debugger without executing
.

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. the first click to log in is refreshed, with an extra question mark at the end of the path

clipboard.png

  1. ,

clipboard.png

4.debugger,

clipboard.png

Mar.23,2021

you used the form form. However, none of your input has a name attribute. You should stop bubbling or default events during onSubmit. Or remove the el-form component. Because there is no need, adding form is nothing more than pressing enter in two input to automatically submit.
that's it


I also have a question mark in url because of the form form submission event mentioned in the comments above.
my solution is to use click.prevent to block default events, which is fine.
< button @ click.prevent= "onSubmit": plain= "true" > sign in < / button >


it seems that button defaults to submit type

change it to type= "button" .

<button type="button"></button>
Menu