he wei
2023-12-23 fc842d9e22aef1946df050257be41b4bfbd838a9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
export default {
  data() {
    return {
      pageFlag: 0,
    };
  },
  beforeRouteEnter(to, from, next) {
    next((vm) => {
      // 由于页面跳转后,在跳转页面筛选后,切换页面后会自动恢复,因此跳转页面需要定义一个方法refreshFN 在里面定义需要执行的代码
      if (vm.refreshFN && "function" == typeof vm.refreshFN) {
        // let pageFlag = vm.$route.query.pageFlag
        //   ? Number(vm.$route.query.pageFlag)
        //   : 0;
        // console.log(pageFlag + "&&&&&" + vm.pageFlag, vm.$data);
        // if (pageFlag !== vm.pageFlag) {
        //   console.log('refresh');
        //   vm.refreshFN();
        //   // vm.pageFlag = pageFlag;
        // }
        // 新版本此处获取不到vm实例的响应属性 故改为在页面refreshFN中判断
        vm.refreshFN();
      }
 
      // 由于页面从非激活状态激活时 不会触发mounted 如果有需求需要定义一个方法 activeFN 在里面定义需要执行的代码
      if (vm.activeFN && "function" == typeof vm.activeFN) {
        vm.activeFN();
      }
    });
  },
  activated() {
    // 如果有websocket 则初始化
    if (this.openSocket && "function" == typeof this.openSocket) {
      this.openSocket();
    }
  },
  deactivated() {
    // 如果有 则关闭websocket
    if (this.WSClose && "function" == typeof this.WSClose) {
      this.WSClose();
    }
    // TODO
    if (this.refreshFN && "function" == typeof this.refreshFN) {
      let pageFlag = this.$route.query.pageFlag
      ? Number(this.$route.query.pageFlag)
      : 0;
      console.log(pageFlag, 'deactive');
      // this.pageFlag = pageFlag;
    }
  },
};