//wxml
<web-view src="{{webSrc}}"></web-view>
//js
Page({ data: { webSrc:'' }, onLoad: function (options) { // const { src } = unescape(options); var src = unescape(options.src) // var src = JSON.parse(decodeURIComponent(options.src)); console.log(src) this.setData({ webSrc: src }) }, // var cityName = wx.getStorageSync('cityName') // var url = app.httpUtil.baseUrl + 'map?cityName=' + cityName; // var jsonUrl = JSON.stringify(encodeURIComponent(url)); // wx.navigateTo({ // url: '../webview/webview?webSrc=' + jsonUrl, // }) // commitShareTimes(urlStr) { // var type = 0; // if(getApp().stringUtil.isEmpty(urlStr)){ // return; // } // if (urlStr.indexOf("super/index") > 0) { // type = 2; // } else if (urlStr.indexOf("super/paper") > 0) { // type = 3; // } else if (urlStr.indexOf("super/storePaper") > 0) { // type = 4; // } else if (urlStr.indexOf("super/weekly") > 0) { // type = 5; // } // if (type>0){ // var userId = getApp().isLogin() ? getApp().getUid() : ""; // var deptId = getApp().isLogin() ? getApp().getUserModel().departmentId : 0; // var sData = { "os": "wxmini", "type": type, "userId": userId, "deptId": deptId }; // getApp().httpUtil.postReq("share", sData, function (res) { // }, function (res) { // console.log(res); // }); // } // }, /** * 用户点击右上角分享 */ // onShareAppMessage: function (options) { // //1.option.webViewUrl 这边拿到的就是当前展示webview的url链接 // //2.为了防止链接有中文,倒是IOS打不开使用encodeURIComponent进行转码 // //let return_url = encodeURIComponent(options.webViewUrl); // //这边作为分享打开的页面 // var htmlStr = this.data.web_src; // if (!app.stringUtil.isEmpty(options.htmlUr)){ // htmlStr = options.htmlUr; // }else{ // htmlStr = options.webViewUrl; // } // this.commitShareTimes(htmlStr); // var return_url = JSON.stringify(encodeURIComponent(htmlStr)); // var path = "pages/webview/webview?webSrc=" + return_url; // return { // title: "", //标题 如果不配置则不显示 // path: path,//分享打开的路径 // //imageUrl: nil,//分享的图片,如果不配置就截图 微信的机制 // success: function (res) { // console.log("分享成功啦") // }, // } // }});
-
调用方法
//地图找房function mapHouse() { var cityName = getApp().cityName var url = getApp().api.apiList.hostUrl + 'map?cityName=' + cityName; console.log(url) var jsonUrl = escape(url); wx.navigateTo({ url: '/pages/webView/webView?src=' + jsonUrl, })}