頁面自動(dòng)刷新和注冊(cè)邏輯問題
rt,代碼如下:
<template> ??<div> ????<form?v-if="!isReg"> ??????<label?for="name1">User?Name:?</label> ??????<input?type="text"?id="name1"?v-model="name"><br> ??????<label?for="pwd1">Password:?</label> ??????<input?type="password"?id="pwd1"?v-model="pwd"><br> ??????<button?@click="login()">Login</button> ??????<button?@click="reg()">register</button> ????</form> ????<form?v-else> ??????<label?for="name2">User?Name:?</label> ??????<input?type="text"?id="name2"?v-model="name"><br> ??????<label?for="pwd2">Password:?</label> ??????<input?type="password"?id="pwd2"?v-model="pwd"><br> ??????<label?for="pwda">Password?Again:?</label> ??????<input?type="password"?id="pwda"?v-model="pwda"><br> ??????<button?@click="confirm()">confirm?register</button> ??????<button?@click="cancel()">cancel?register</button> ????</form> ??</div> </template>
login()?{ ??this.$router.push('home') }, reg()?{ ??this.isReg?=?true }, cancel()?{ ??this.isReg?=?false }, confirm()?{ ??if(this.pwd?===?this.pwda?&&?this.name?!==?''?&&?this.pwd?!==?'')?{ ????localStorage.setItem('name',this.name) ????localStorage.setItem('pwd',this.pwd) ????this.name?=?'' ????this.pwd?=?'' ????this.isReg?=?false ??}?else?{ ????alert("兩次輸入不一致") ??} }
沒有報(bào)錯(cuò),問題在于點(diǎn)擊任意按鈕時(shí)頁面都會(huì)自動(dòng)刷新,這就導(dǎo)致點(diǎn)擊注冊(cè)時(shí),注冊(cè)表單一閃而過刷新回登錄,此時(shí)url為localhost:8080/?,我重啟服務(wù)、瀏覽器都沒有用。
還有最后這個(gè)confirm函數(shù),空信息注冊(cè)會(huì)彈窗,但是localstorage也會(huì)存數(shù)據(jù),相當(dāng)于兩個(gè)分支都走了一遍,有點(diǎn)不可思議,是我判斷的條件有問題嗎?
有點(diǎn)懵,還請(qǐng)賜教。
2019-05-30
試試,button 加一個(gè)type="button"
2019-10-24
完美解決??