小程序 向 web-view 传值

微信小程序:
x.js:
onLoad: function (options) {
    var app = getApp();
    var nickName = encodeURI(app.globalData.userInfo.nickName);
    this.setData({
      userInfo: app.globalData.userInfo,
      nickName: nickName
    })
  },

x.wxml:



前端页面:
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");

    var url =decodeURI(decodeURI(window.location.search)); //获取url中"?"符后的字串,使用了两次decodeRUI解码

    var r = url.substr(1).match(reg); //匹配目标参数
    if(r != null) return unescape(r[2]);
    return null; //返回参数值
}


var avatarUrl = getUrlParam('avatarUrl')
if (avatarUrl) {
    $('.user-avatar').attr('src',getUrlParam('avatarUrl'));
}
    $('.user-nickname').html(getUrlParam('nickName'));                                                
}

你可能感兴趣的:(小程序 向 web-view 传值)