官方文檔
React中實踐參考
第一步,引入官方文檔的js:
<DynamicScript url = {`https://res2.wx.qq.com/open/js/jweixin‐1.6.0.js`}
onLoadHandle={this.onWxLoadHandle}
>
</DynamicScript>
第二步,初始化和格式化:
wxConfigHandle = (configData)=>{
let self = this;
try{
wx.config({
debug: false, // 開啟調(diào)試模式,調(diào)用的所有api的返回值會在客戶端alert出來,若
要查看傳入的參數(shù),可以在pc端打開,參數(shù)信息會通過log打出,僅在pc端時才會打印。
appId: configData.appId, // 必填,公眾號的唯一標識
timestamp: configData.timestamp, // 必填,生成簽名的時間戳
nonceStr: configData.nonceStr, // 必填,生成簽名的隨機串
signature: configData.signature,// 必填,簽名
jsApiList: ['updateAppMessageShareData', 'onMenuShareTimeline',
'hideMenuItems'],// 必填,需要使用的JS接口列表
openTagList: ['wx‐open‐launch‐weapp']
});
wx.ready(function(){
// config信息驗證后會執(zhí)行ready方法,所有接口調(diào)用都必須在config接口獲得結(jié)果之
后,config是一個客戶端的異步操作,所以如果需要在頁面加載時就調(diào)用相關(guān)接口,則須把相關(guān)接口放在
ready函數(shù)中調(diào)用來確保正確執(zhí)行。對于用戶觸發(fā)時才調(diào)用的接口,則可以直接調(diào)用,不需要放在ready函數(shù)
中。
wx.hideMenuItems({
menuList: ['menuItem:share:appMessage', 'menuItem:share:timeline',
'menuItem:share:qq', 'menuItem:share:weiboApp',
'menuItem:favorite', 'menuItem:share:facebook',
'menuItem:share:QZone',
'menuItem:originPage', 'menuItem:openWithQQBrowser',
'menuItem:copyUrl',
'menuItem:openWithSafari', 'menuItem:share:email',
'menuItem:share:brand',
]
});
// gh_xxxxxxx
// pages/index/index.html
self.setState({
wxTag: `<wx‐open‐launch‐weapp
id="launch‐btn"
username="gh_xxxxxxx"
path="pages/index/index.html"
>
<template>
<style>.btn { padding: 12px;}</style>
<button class="btn">打開小程序</button>
</template>
</wx‐open‐launch‐weapp>`
})
});
}catch (e){
}
}
第三步,頁面加載:
<div dangerouslySetInnerHTML={{__html: wxTag}} />
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。