微信小程序生成二維碼之傳參(接收的參數亂碼該咋解決)


先說我的案例,我需要的是,掃碼進入不同的區域展示(因此這個就需要進行二維碼路徑傳參),大致思路:接收數據,然后根據所接收的數據進行判斷,展示不同的區域。

我是用的草料二維碼生成的 - https://cli.im/weapp

路徑是這樣的:pages/addPage/addPage?location=阿里爸爸

在我通過生成的二維碼進入的時候發現,我得到的參數,是被微信小程序轉譯后的(\u963f\u91cc\u7238\u7238)不是我所需要的內容。轉譯地址:http://www.jsons.cn/unicode/

因此,我們就需要轉譯,通過所接收的參數進行轉譯然后得到正確的字符(阿里爸爸)

下串代碼只做接收並進行轉譯操作

onLoad(option){
    this.currentLocation = option.location;
    //默認如果沒有傳輸地址就為嘻嘻
    if (!this.currentLocation || this.currentLocation === undefined || this.currentLocation.trim() === '') {
        this.currentLocation = '嘻嘻';
    } else if (this.currentLocation.indexOf('\\u') != -1) {
        // UNICODE轉中文
        this.currentLocation = unescape(this.currentLocation.replace(/\\u/g, '%u'));
    } else if (this.currentLocation.indexOf('%') != -1) {
        // encodeURI 轉中文
        this.currentLocation = decodeURI(this.currentLocation);
    }
}

 


免責聲明!

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



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