我正在VueJS应用程序上工作,我想从vuex存储中监视用户状态的变化并执行某些操作。正在进行更改,但未触发监视钩。
这是计算出的属性和手表的代码。
computed: {
formIsValid() {
return (
this.form.company &&
this.form.street &&
this.form.phone &&
this.form.selectedRole &&
this.form.selectedStatus &&
this.form.email &&
this.form.industry &&
this.form.password
);
},
user() {
this.$store.getters.getUser;
console.log("Computed" + this.$store.getters.getUser.id);
}
},
watch: {
user(value) {
console.log("A change has occured");
console.log({ user: value });
if (value !== null && value !== undefined) {
console.log("ama is going");
this.$router.push({ name: "Jobs" });
} else {
console.log("The thing is null");
}
}
},
在user
计算方法中,您不是return
-值。我怀疑您是否在Vue devtools中进行了计算:用户的值为undefined
。
我相信您的更改应该是...
computed: {
user() {
console.log("Computed" + this.$store.getters.getUser.id);
return this.$store.getters.getUser;
}
}