{"id":1602,"date":"2023-03-25T20:09:50","date_gmt":"2023-03-25T12:09:50","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1602"},"modified":"2023-04-27T21:23:51","modified_gmt":"2023-04-27T13:23:51","slug":"wechat-payment-in-vue-displays-the-issue-of-weixinjsbridge-being-not-defined","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/25\/wechat-payment-in-vue-displays-the-issue-of-weixinjsbridge-being-not-defined\/","title":{"rendered":"Vue \u4e2d\u5fae\u4fe1\u652f\u4ed8\uff0c\u663e\u793aWeiXinJSBridge is not defined\u7684\u95ee\u9898"},"content":{"rendered":"<p>\u52ff\u5728created\u4e2d\u89e6\u53d1\uff0c\u901a\u8fc7button\u70b9\u51fb\u89e6\u53d1\u6216\u8005\u5ef6\u65f6\u89e6\u53d1\uff0c\u76ee\u7684\u662f\u7b49\u5f85WeixinJSBridge\u52a0\u8f7d\u5b8c\u6bd5<\/p>\n<pre><code class=\"language-javascript\">created() {\n  let _this = this;\n  setTimeout(() =&gt; {\n    _this.pay(_this.payment);\n  }, 3000);\n},<\/code><\/pre>\n<p><!-- more --><\/p>\n<pre><code class=\"language-javascript\">var vm = this;\nif (typeof WeixinJSBridge == &quot;undefined&quot;) {\/\/\u5fae\u4fe1\u6d4f\u89c8\u5668\u5185\u7f6e\u5bf9\u8c61\u3002\u53c2\u8003\u5fae\u4fe1\u5b98\u65b9\u6587\u6863\n  if (document.addEventListener) {\n    document.addEventListener(&#039;WeixinJSBridgeReady&#039;, vm.onBridgeReady(data), false);\n  } else if (document.attachEvent) {\n    document.attachEvent(&#039;WeixinJSBridgeReady&#039;, vm.onBridgeReady(data));\n    document.attachEvent(&#039;onWeixinJSBridgeReady&#039;,vm.onBridgeReady(data));\n  }\n} else {\n  vm.onBridgeReady(data);\n}\n\nonBridgeReady: function(data) {\n  var vm = this;\n  WeixinJSBridge.invoke(\n    &#039;getBrandWCPayRequest&#039;, {\n    debug:true,\n    &quot;appId&quot;:data.appId,\/\/\u516c\u4f17\u53f7\u540d\u79f0\uff0c\u7531\u5546\u6237\u4f20\u5165\n    &quot;timeStamp&quot;:data.timeStamp,\/\/\u65f6\u95f4\u6233\n    &quot;nonceStr&quot;:data.nonceStr,\/\/\u968f\u673a\u4e32\n    &quot;package&quot;:data.packageValue,\/\/\u9884\u652f\u4ed8id\n    &quot;signType&quot;:data.signType,\/\/\u5fae\u4fe1\u7b7e\u540d\u65b9\u5f0f\n    &quot;paySign&quot;:data.paySign,\/\/\u5fae\u4fe1\u7b7e\u540d\n  },\n  function(res) {\n    console.log(res.err_msg)\n    \/\/debugger;\n    \/\/ \u4f7f\u7528\u4ee5\u4e0a\u65b9\u5f0f\u5224\u65ad\u524d\u7aef\u8fd4\u56de,\u5fae\u4fe1\u56e2\u961f\u90d1\u91cd\u63d0\u793a\uff1ares.err_msg\u5c06\u5728\u7528\u6237\u652f\u4ed8\u6210\u529f\u540e\u8fd4\u56deok\uff0c\u4f46\u5e76\u4e0d\u4fdd\u8bc1\u5b83\u7edd\u5bf9\u53ef\u9760\u3002\n    if (res.err_msg == &quot;get_brand_wcpay_request\uff1aok&quot;) {\n      alert(&quot;\u652f\u4ed8\u6210\u529f&quot;)\n      \/\/vm.$router.push(&quot;\/reservedBerth&quot;);\n    } else {\n      \/\/alert(&quot;\u652f\u4ed8\u5931\u8d25,\u8bf7\u8df3\u8f6c\u9875\u9762&quot;+res.err_msg);\n    }\n  });\n},<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u52ff\u5728created\u4e2d\u89e6\u53d1\uff0c\u901a\u8fc7button\u70b9\u51fb\u89e6\u53d1\u6216\u8005\u5ef6\u65f6\u89e6\u53d1\uff0c\u76ee\u7684\u662f\u7b49\u5f85WeixinJSBridge\u52a0\u8f7d\u5b8c\u6bd5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35,371],"tags":[320],"class_list":["post-1602","post","type-post","status-publish","format-standard","hentry","category-vue","category-wechat-pay","tag-jsbridge"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1602","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1602"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1602\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1602"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}