美文网首页
uniapp扫描带参数的小程序码

uniapp扫描带参数的小程序码

作者: ToBeRichGirl | 来源:发表于2020-05-26 10:43 被阅读0次

<script>

export default {

    onLaunch: function(options) {

        console.log("onLaunch",options);

        if(options.query.scene){ //小程序码是否带有参数

            //params转 obj  字符串参数  a=123&b=456 转 {a:"123",b:"456"}

            var query=this.getRequestParameters(decodeURIComponent(options.query.scene))

            console.log("onLaunch",query);

            //对获取到的参数query进行下一步操作

        }

    },

    onShow: function() {

        console.log('App Show')

    },

    onHide: function() {

        console.log('App Hide')

    },

     methods:{

            /*

            * params转 obj  字符串参数

            * 例子: a=1&b=2 => {a:1,b:2}

            */

            getRequestParameters(params="") {

                let theRequest = new Object();

                if (params != undefined) {

                    let strs = params.split("&");

                    for (let i = 0; i < strs.length; i++) {

                        theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);

                    }

                }

                return theRequest;

             },

        }

}

</script> 

相关文章

网友评论

      本文标题:uniapp扫描带参数的小程序码

      本文链接:https://www.haomeiwen.com/subject/lddmahtx.html