简体   繁体   English

/?#/ 在带有 Vue-router 的 Vue 中是什么意思?

[英]What does /?#/ mean in Vue with Vue-router?

Hi everyone I have a bug with my page.大家好,我的页面有错误。 When I click on a button it automatically refreshes the page (which i don't want) but with the ?# as from http://127.0.0.1:8080/#/Login .当我单击一个按钮时,它会自动刷新页面(我不想要),但使用?#http://127.0.0.1:8080/#/Login

it refreshes to http://127.0.0.1:8080/?#/Login then it works normally.它刷新到http://127.0.0.1:8080/?#/Login然后它可以正常工作。 I know that the # is for Vue-router but what's the ?我知道#是针对 Vue-router 的,但 是什么? for?为了?

Here is my code:这是我的代码:

<template>
  <v-content class="login">
    <v-card
      class="mx-auto"
      max-width="400"
      max-height="1000"
    >
    <v-list-item>
      <v-list-item-content>
        <v-list-item-title class="headline">{{$t("loginPage.title")}}</v-list-item-title>
        <v-list-item-subtitle>{{$t("loginPage.subtitle")}}</v-list-item-subtitle>
      </v-list-item-content>
    </v-list-item>
      <v-form class="login" v-model="loginForm">
        <v-card-text>
          <v-text-field
            :label="$t('loginPage.username')"
            solo
            type="text"
            required
            :rules="userNameRules"
            v-model="username"
          >
          </v-text-field>
          <v-text-field
            :label="$t('loginPage.password')"
            solo
            :append-icon="showPassword ? 'mdi-eye' : 'mdi-eye-off'"
            :type="showPassword ? 'text' : 'password'"
            @click:append="showPassword = !showPassword"
            :rules="passwordRules"
            required
            v-model="password"
          >
          </v-text-field>
        </v-card-text>
        <v-card-actions>
          <v-btn
            @click="login"
            tile
            :disabled="!loginForm"
            :loading="loadingButton"
            color="primary"
            block
            type="submit"
            >{{$t('loginPage.loginButton')}}
          </v-btn>
        </v-card-actions>
      </v-form>
    </v-card>
    <v-container>
      <v-row justify="center">
        <v-col cols="12" md='4'>
          <v-alert type="error" v-if='loginError'>{{ $t('loginPage.errorLoging') }}</v-alert>
          <v-alert type="warning" v-if='logged'>{{ $t('loginPage.alreadyLoged', {user: currentUsername}) }}</v-alert>
        </v-col>
      </v-row>
    </v-container>
  </v-content>
</template>

<script>
export default {
  /* eslint-disable */
  name: 'Login',
  data () {
    return {
      username: '',
      password: '',
      showPassword: false,
      loginError: false,
      logged: false,
      currentUsername: '',
      loginForm: false,
      userNameRules: [
        v => !!v || this.$t('loginPage.isRequired', {leOula: 'Le', item: this.$t('loginPage.username')})
      ],
      passwordRules: [
        v => !!v || this.$t('loginPage.isRequired', {leOula: 'Le', item: this.$t('loginPage.password')})
      ],
      loadingButton: false
    }
  },
  mounted: function () {
    console.log("mounted function called")
  },
  methods: {
    login: function () {

      console.log("login function called")
    }
  }
}
</script>

This happens because you're using a <v-form> which is submitting the form on the page.发生这种情况是因为您使用的是在页面上提交表单的<v-form> To prevent this default form submit functionality, use the prevent modifier on the form's submit handler:要阻止此默认表单提交功能,请在表单的submit处理程序上使用prevent修饰符:

<v-form class="login" v-model="loginForm" @submit.prevent="login">

This will also call the login method, so you should remove the @click handler from the button.这也将调用login方法,因此您应该从按钮中删除@click处理程序。

Or you could leave the handler on the button and remove it from the @submit handler:或者您可以将处理程序留在按钮上并将其从@submit处理程序中删除:

<v-form class="login" v-model="loginForm" @submit.prevent>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM