出現一個問題,點擊“注冊”按鈕頁面進入注冊表單后自動跳轉回登錄頁面
<template>
????<div>
????????<form?v-if="!isReg">
????????????用戶名:
????????????<input?type="text"?v-model="name">
????????????密碼:
????????????<input?type="text"?v-model="password">
????????????<button?type="button"?@click="login()">登錄</button>
????????????<button?type="button"?@click="reg()">注冊</button>
????????</form>
????????<form?v-else>
????????????用戶名:
????????????<input?type="text"?v-model="name">
????????????密碼:
????????????<input?type="text"?v-model="password">
????????????再次輸入密碼:
????????????<input?type="text">
????????????<button?@click="addUser()">確定</button>
????????????<button?@click="cancel()">取消</button>
????????</form>
????</div>
?</template>
?<script>
?export?default?{
?????name:?"Login",
?????data?()?{
?????????return?{
?????????????isReg:?false,
?????????????name:?'',
?????????????password:?'',
?????????????repeat:?''
?????????}
?????},
?????methods:?{
?????????login?()?{
?????????????this.$router.push('/home/list')
?????????},
?????????reg?()?{
?????????????this.isReg?=?true
?????????},
?????????cancel?()?{
?????????????this.isReg?=?false
?????????},
?????????addUser?()?{
?????????????localStorage.setItem("name",?this.name)
?????????????localStorage.setItem("password",?this.password)
?????????}
??????}
???}
</script>
<style>
</style>請問老師如何解決bug?
2019-02-11
1. form標簽的action屬性會進行跳轉,所以form不給action標簽,
2. 在button上的type不使用submit,因為submit會默認執行action屬性;
3. 在form標簽、click上加入prevent修飾符,參考:修飾符,事件修飾符
2019-07-04
第一個form表單中的button標簽更換為div標簽就不會有上訴問題了
2019-03-14
我也是這樣?但是不知道為啥。代碼和視頻里一模一樣的?自己會跳轉回去
2019-02-09
已找到問題所在,是因為form標簽所導致的,換成div標簽就沒有問題了,但是不知道為什么會產生這問題