方法一
function onBridgeReady() {
WeixinJSBridge.call('hideOptionMenu');
}
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
}
} else {
onBridgeReady();
}
方法二
先安装weixin-js-sdk
npm install weixin-js-sdk
引入
import wx from ‘weixin-js-sdk’;
使用
this.$axios.post('/weixin/get',{'url':location.href.split('#')[0]}).then((response)=> {
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: response.appid, // 必填,公众号的唯一标识
timestamp: response.timestamp, // 必填,生成签名的时间戳
nonceStr: response.nonceStr, // 必填,生成签名的随机串
signature: response.signature,// 必填,签名
jsApiList: [ 'hideMenuItems'] // 必填,需要使用的JS接口列表
});
wx.ready(function () {
wx.hideMenuItems({
menuList: ['menuItem:share:appMessage', 'menuItem:share:timeline', 'menuItem:share:qq', 'menuItem:share:QZone', 'menuItem:openWithSafari', 'menuItem:openWithQQBrowser', 'menuItem:favorite','menuItem:share:facebook','menuItem:share:weiboApp','menuItem:copyUrl','menuItem:openWithQQBrowser','menuItem:openWithSafari'],
});
wx.hideAllNonBaseMenuItem();
});
wx.error(function (res) {
// alert('wx.error: '+JSON.stringify(res));
});
})
公众号文档 https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#2
微信返回码说明:https://developers.weixin.qq.com/doc/offiaccount/Getting_Started/Global_Return_Code.html