The H5 page written by VUE cannot respond to the app WeChat payment result callback!

There is a problem in the written H5 page in the mobile app. After running WeChat payment, a result callback notification will be sent to the H5 page. Often the methods we wrote inside the component cannot respond.

Inside the script tag:

insert image description here

In the methods inside the component:

insert image description here

It is unresponsive in the script tag or methods inside the component.

Approach:

And write the response method in main.js, the window object registered in the browser can respond!

window.onPayResult = function (code) {
    
    
   alert("按键code="+code);
   if (code == 0) {
    
    
     alert("成功");
   } else if(code==1) {
    
    
     alert("失败");
   }else{
    
    
     alert("用户取消");
   }
    // "0"成功 “1”失败,"2"用户取消
}

Guess you like

Origin blog.csdn.net/lyf976229437/article/details/109195462