vue.js - Vuejs state seems to only update in a setTimeout -
this component object:
<script> import { ipcrenderer } 'electron'; export default { data() { return { "formdata": { "username": "", "password": "", "auth_code": "", "auth_code_required": false, "submitted": false, "showformscreen": true }, "showwelcomescreen": false, "state": { "value": 0, "message": "" } } }, computed: { statemessageshow() { return (this.state.value !== 0 || this.state.value === 999); } }, mounted() { ipcrenderer.on('loginresponse', (e, a) => { this.formdata.submitted = false; switch(a.state) { // successful login case 1: this.formdata.showformscreen = false; settimeout(()=> { this.state = { value: 0 }; this.showwelcomescreen = true; }, 2000) break; // invalid form data case 5: this.state = { value: 999, message: "incorrect email or password" }; break; // auth code required case 63: case 65: vue.nexttick(() => { this.state = { value: 0, message: "" }; this.formdata.auth_code_required = true; }) break; } this.formdata.submitted = false; }); ipcrenderer.on('loginattemptupdate', (e, a) => { switch(a.state) { case 1: this.state = { value: a.state, message: "connecting"}; break; case 2: this.state = { value: a.state, message: "connected" }; break; case 3: this.state = { value: a.state, message: "logging in"}; break; case 4: this.state = { value: a.state, message: "logged in successfully" }; break; case 5: this.state = { value: a.state, message: "login attempt failed" }; break; default: this.state = { value: 0, message: "" }; break; } }); }, methods: { onsubmit() { this.formdata.submitted = true; if (this.$store.state.user.isloggedin) return; ipcrenderer.send('clientlogin', this.formdata); } } } </script>
i found out accidentally, state change if wrap this.blah = foo
in settimeout, changes fine. if try set state in case
nothing happens.
i have no idea if intended, or why it's happening information great
Comments
Post a Comment