如图所示:
功能要求 当点击 又上角的 asdaf123 时,页面需要 重新获取api.
实现想法:使用vuex,当mutations 改变state状态,在页面监听,则可重新发请求 获取列表
在点击 左上角时
在header 组件中:
if(this.$route.path==='/setting/xxxxx'){
this.$store.commit("noticePageMutation", Math.random(1,100));
}
mutations:
state: {
randomNum: 0
},
mutations: {
noticePageMutation(state, payload) {
state.randomNum = payload;
console.error(state.randomNum);
}
}
getter.js:
const getters = {
randomNum: state => state.notice.randomNum
};
export default getters;
notice page 页面:
import { mapGetters } from "vuex";
computed: {
...mapGetters(["randomNum"]),
},
watch: {
randomNum(randomNum) {
this.getNoticesListPage();// 发请求拉取api
},
},