研发图纸文件管理系统-前端项目
he wei
2022-08-13 8693ce242a84316a6d83a2bb9f26c959b7411618
UA 当页面不活动时 关闭websocket
1个文件已修改
1个文件已添加
26 ■■■■■ 已修改文件
src/assets/js/beforeRouteChange.js 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main.js 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/assets/js/beforeRouteChange.js
New file
@@ -0,0 +1,22 @@
export default {
  beforeRouteEnter(to, from, next) {
    next((vm) => {
      // 由于页面从非激活状态激活时 不会触发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();
    }
  }
}
src/main.js
@@ -13,6 +13,7 @@
import 'moment/locale/zh-cn'
import layer from 'vue-layer'
import 'vue-layer/lib/vue-layer.css'
import beforeRouteChange from './assets/js/beforeRouteChange'
Vue.prototype.$layer = layer(Vue);
@@ -24,6 +25,9 @@
Vue.use(Viser)
Vue.use(Plugins)
// 全局混入页面路由守卫
Vue.mixin(beforeRouteChange);
bootstrap({router, store, i18n, message: Vue.prototype.$message})
new Vue({