vue 混合方法mixins 协可以写入公共的方法

新建一个文件夹mixins  同views 同级

export default {
  data() {
    return {
    };
  },
  mounted() {
  },
  methods: {
    // 修改标题方法
    ready(callback) {
      // 如果 jsbridge 已经注入则直接调用
      if (window.AlipayJSBridge) {
        callback && callback();
      } else {
        // 如果没有注入则监听注入的事件
        document.addEventListener('AlipayJSBridgeReady', callback, false);
      }
    },
  }
}

 然后在main.js中引入 (公共的 )

import mixin from '@/mixins';
// 全局混入
Vue.mixin(mixin);

 最后在页面中调用   此方法为标题修改

  created() {
    this.ready(() => {
      AlipayJSBridge.call('setTitle', {title: '组织变更用户权限处理',}, res => {
      });
    })
  },

 

posted @ 2024-07-12 10:10  bingxiaoxiao  阅读(2)  评论(0编辑  收藏  举报