需求是这样的,从任意页logout跳回登录页,account初始化为上一次登录的账号。 那我就登录成功后存了一次account到state备用
<template>
<form class="content">
<input type="phone" placeholder="手机号" v-model="account" />
<input type="password" placeholder="密码" v-model="password" />
<a @click="login">登录</a>
</form>
</template>
<script>
export default {
data() {
return {
account: "",
password: ""
};
},
computed: {
lastAccount:{
get(){
this.account = this.$store.state.account;
return this.$store.state.account;
}
}
},
watch:{
lastAccount(newVal){
//对,这里为空,但是注释掉这个watcher之后就没法给account赋值了
}
}
};
</script>