Vue丨将组件 methods 内的方法绑定到 window 来调用

在Vue项目中,由于作用域和异步执行的问题,导致组件内的methods方法无法在第三方组件中或外部正确执行。通过将methods中的方法绑定到window对象,确保了在第三方组件完成时能够正确调用,从而解决了执行顺序问题。欢迎分享不同的解决方案进行交流学习。
摘要由CSDN通过智能技术生成
methods:{
  // 创建电话组件
  createCallComponent(phoneNum) {
    if (window.callComp && !window.callComp.isDestroyed) {
      return;
    };
    window.callComp = new UdeskCallcenterComponent({
       container: document.body,
       token: this.agentToken,
       subDomain: this.subDomain,
       showManualScreenPop: false,
       onHangup: function(conversation) { // 电话挂断时执行
         getCallId(conversation.call_id);  // 这里调用绑定后的方法,并传入callid
         window.callComp.destroy(); // 销毁电话组件
         window.callComp = null; // 销毁电话组件</
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值