uniapp開發的app打開微信小程序


第一種

<script>
    export default {
        data() {
            return {
                sweixin: null
            }
        },
        onLoad() {
            this.getPlus() 
        },
        methods: { 
            getPlus() {
                //獲取當前顯示的webview
                var pages = getCurrentPages()
                var page = pages[pages.length - 1]
                var currentWebview = page.$getAppWebview()
                //調用H5+APP的擴展API
                var shares = null;
                let that = this
                var pusher = plus.share.getServices(function(s) {
                    shares = {};
                    for (var i in s) {
                        var t = s[i];
                        shares[t.id] = t;
                    }
                    that.sweixin = shares['weixin'];
                }, function(e) {
                    console.log("獲取分享服務列表失敗:" + e.message);
                });
                //放入當前的webview
                currentWebview.append(pusher);
            },
            checkWeChat() {
                //調用微信小程序  
                if(this.sweixin){ 
                    this.sweixin.launchMiniProgram({
                        id: '' //要跳轉小程序的原始ID
                    }) 
                }  

            } 
        }
    }
</script>

第二種

plus.share.getServices(
    res => {
        let sweixin = null;
        for (let i in res) {
            if (res[i].id == 'weixin') {
                sweixin = res[i];
            }
        }
        //喚醒微信小程序
        if (sweixin) {
            sweixin.launchMiniProgram({
                id: 'gh_0720325777cc', //
                type: 0, //小程序版本  0-正式版; 1-測試版; 2-體驗版。
                // path: 'pages/index/index?id=' + 1 //小程序的頁面,用傳的參數在小程序接值判斷跳轉指定頁面
            });
        }
    }
);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM