webview向html传中文乱码uniapp

下为.vue页面

先对webview传参进行编码,如图webview是通过src进行传值

如下图为src向html传值的参数,其中toUserName为中文,我们对toUserName进行编码,建议使用encodeURIComponent()进行编码

encodeURIComponent(this.toUserName)//encodeURIComponent(data.data)

下为.html页面

将webview传过来的参数进行解码,采用decodeURI()

//获取地址栏URL中参数,采用 getQuery()
function getQuery(toUserName) {
            var query = window.location.search.substring(1);
            var map = query.split("&");
            for (var i = 0; i < map.length; i++) {
                var pair = map[i].split("=");
                if (pair[0] == toUserName) {
                    return pair[1];
                }
            }
        }
//采用decodeURI(data)进行解码
var toUserName=decodeURI(getQuery("toUserName"));
//console.log(toUserName)

猜你喜欢

转载自blog.csdn.net/qq_35353972/article/details/128692713