出現(xiàn)一個問題,點擊“注冊”按鈕頁面進(jìn)入注冊表單后自動跳轉(zhuǎn)回登錄頁面
<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標(biāo)簽的action屬性會進(jìn)行跳轉(zhuǎn),所以form不給action標(biāo)簽,
2. 在button上的type不使用submit,因為submit會默認(rèn)執(zhí)行action屬性;
3. 在form標(biāo)簽、click上加入prevent修飾符,參考:修飾符,事件修飾符
2019-07-04
第一個form表單中的button標(biāo)簽更換為div標(biāo)簽就不會有上訴問題了
2019-03-14
我也是這樣?但是不知道為啥。代碼和視頻里一模一樣的?自己會跳轉(zhuǎn)回去
2019-02-09
已找到問題所在,是因為form標(biāo)簽所導(dǎo)致的,換成div標(biāo)簽就沒有問題了,但是不知道為什么會產(chǎn)生這問題