Vue脚手架项目中遇到的问题总结

vue中hash路由跳转时url路径被加问号

http://localhost:8081/?#/BroadbandPay

原因

你使用了 form 表单。 应该在 onSubmit 时 阻止下冒泡或默认事件 就可以了。

比如,下面的代码就是一个错误案例,form表单中使用button进行了提交

<form>
  <input v-model="user.account" type="text" placeholder="请输入用户名" required>
  <input v-model="user.password" type="password" placeholder="请输入用户密码" required>
  <button  @click="axios_StudentLogin">登录</button >
</form>

解决方法1

把button提出来

<form>
  <input v-model="user.account" type="text" placeholder="请输入用户名" required>
  <input v-model="user.password" type="password" placeholder="请输入用户密码" required>
</form>
<button  @click="axios_StudentLogin">登录</button >

解决方法2

使用click.prevent阻止默认事件,就好了。

<form>
  <input v-model="user.account" type="text" placeholder="请输入用户名" required>
  <input v-model="user.password" type="password" placeholder="请输入用户密码" required>
  <button  @click.prevent="axios_StudentLogin">登录</button >
</form>                    

猜你喜欢

转载自blog.csdn.net/qq_39123467/article/details/129872885