created() { this.userId = this.$store.getters.userid; this.fetchData(); // 发送请求

this.$watch(() => this.$store.getters.userid, (newUserId) => { this.userId = newUserId; this.fetchData(); // 发送请求 }, { immediate: true, deep: true }); }, methods: { fetchData() { // 发送请求的逻辑 } }

vue2监听this$storegettersuserid 发生变化后赋值给thisuserId并发送请求 created thisuserId = this$storegettersuserid; thisfetchData; 发送请求watch $storegettersuserid functionnewUserId thisuserId = newUserId;

原文地址: https://www.cveoy.top/t/topic/ikOE 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录