问题已经自己解决,是后端写html的时候默认是Unicode,改成UTF-8就可以了
代码在开发者工具正常运行,到小程序体验版就报错undefined is not an object?[图片] 在开发者工具上,可以正常切割html,切割body,保留body以内的部分,再用rich-text富文本进行解析 即可显示,功能一切正常。 [图片] [图片] 在手机上端就会报错,经调试发现 res.data是有值的,其为html的内容,数据类型是字符串,但是 [代码]var[代码] [代码]imgus = imgu.split([代码][代码]'body'[代码][代码]); [代码]这一行代码, split() 函数实际上并没有执行,因为后面打印的split后面的内容imgus是只包含一个元素的数组,其值还是 之前的html数据 ,没有变。 但是在我的小程序的其他界面也用到过split()函数,在手机体验版上运行 并没有任何问题。因此想咨询一下 这下什么问题?是不是微信小程序体验版的bug? [代码][代码] [代码]// pages/comment/newsDetail.js[代码][代码]const tip = require([代码][代码]'../../utils/tip.js'[代码][代码]);[代码][代码]const api = require([代码][代码]'../../utils/api.js'[代码][代码]);[代码][代码]var[代码] [代码]WxParse = require([代码][代码]'../../utils/wxParse/wxParse.js'[代码][代码]);[代码][代码]var[代码] [代码]app = getApp()[代码][代码]Page({[代码] [代码] [代码][代码]/**[代码][代码] [代码][代码]* 页面的初始数据[代码][代码] [代码][代码]*/[代码][代码] [代码][代码]data: {[代码][代码] [代码][代码]nodes: [代码][代码]''[代码][代码],[代码][代码] [代码][代码]url: [代码][代码]''[代码][代码] [代码][代码]},[代码] [代码] [代码][代码]/**[代码][代码] [代码][代码]* 生命周期函数--监听页面加载[代码][代码] [代码][代码]*/[代码][代码] [代码][代码]onLoad: [代码][代码]function[代码] [代码](options) {[代码][代码] [代码][代码]console.log([代码][代码]"测试11112222"[代码][代码]);[代码][代码] [代码][代码]//console.log(app.globalData.newsUrl);[代码][代码] [代码][代码]console.log(options.url);[代码] [代码] [代码] [代码] [代码][代码]let that = [代码][代码]this[代码][代码];[代码][代码] [代码][代码]that.setData({[代码][代码] [代码][代码]url: options.url[代码][代码] [代码][代码]})[代码][代码] [代码][代码]this[代码][代码].getNews();[代码][代码] [代码] [代码] [代码] [代码] [代码][代码]},[代码][代码] [代码][代码]//加载新闻[代码][代码] [代码][代码]getNews: [代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]var[代码] [代码]that = [代码][代码]this[代码][代码];[代码][代码] [代码][代码]console.log([代码][代码]"22222222222222222222222222222"[代码][代码]);[代码][代码] [代码][代码]console.log(app.globalData.newsUrl);[代码] [代码] [代码] [代码] [代码][代码]var[代码] [代码]successCallBack = [代码][代码]function[代码] [代码](res) {[代码][代码] [代码] [代码] [代码][代码]console.log(res);[代码][代码] [代码][代码]if[代码] [代码](res.statusCode == [代码][代码]'200'[代码][代码]) {[代码][代码] [代码][代码]console.log([代码][代码]"执行200"[代码][代码]);[代码] [代码] [代码][代码]console.log(res.data);[代码][代码] [代码] [代码] [代码][代码]var[代码] [代码]imgu = res.data;[代码][代码] [代码] [代码] [代码][代码]var[代码] [代码]imgus = imgu.split([代码][代码]'body'[代码][代码]);[代码][代码] [代码][代码]console.log([代码][代码]'imgus'[代码] [代码]+ imgus);[代码][代码] [代码][代码]var[代码] [代码]cutUrl = imgus[1];[代码][代码] [代码][代码]console.log(cutUrl);[代码][代码] [代码][代码]var[代码] [代码]strFin = cutUrl.substr(1, cutUrl.length - 3);[代码][代码] [代码][代码]//console.log('url' + '1111111');[代码][代码] [代码] [代码] [代码][代码]that.setData({ nodes: cutUrl })[代码][代码] [代码] [代码] [代码] [代码] [代码][代码]} [代码][代码]else[代码] [代码]{[代码][代码] [代码][代码]tip.Tips.error(res.data.rtnMsg);[代码][代码] [代码][代码]}[代码] [代码] [代码][代码]};[代码] [代码] [代码][代码]api.getNews({[代码][代码] [代码][代码]query: {[代码] [代码] [代码][代码]url: that.data.url,[代码][代码] [代码][代码]no: [代码][代码]"116"[代码][代码],[代码][代码] [代码][代码]token: app.globalData.token[代码][代码] [代码][代码]},[代码][代码] [代码][代码]header: {[代码][代码] [代码][代码]'content-type'[代码][代码]: [代码][代码]'application/json;charset=UTF-8'[代码][代码] [代码][代码]},[代码][代码] [代码][代码]method: [代码][代码]"POST"[代码][代码],[代码][代码] [代码][代码]appid: [代码][代码]this[代码][代码],[代码][代码] [代码][代码]successCallBack: successCallBack[代码][代码] [代码][代码]});[代码][代码] [代码][代码]},[代码] [代码] [代码][代码]/**[代码][代码] [代码][代码]* 生命周期函数--监听页面初次渲染完成[代码][代码] [代码][代码]*/[代码][代码] [代码][代码]onReady: [代码][代码]function[代码] [代码]() {[代码] [代码] [代码][代码]},[代码] [代码] [代码][代码]/**[代码][代码] [代码][代码]* 生命周期函数--监听页面显示[代码][代码] [代码][代码]*/[代码][代码] [代码][代码]onShow: [代码][代码]function[代码] [代码]() {[代码] [代码] [代码][代码]},[代码] [代码] [代码][代码]/**[代码][代码] [代码][代码]* 生命周期函数--监听页面隐藏[代码][代码] [代码][代码]*/[代码][代码] [代码][代码]onHide: [代码][代码]function[代码] [代码]() {[代码] [代码] [代码][代码]},[代码] [代码] [代码][代码]/**[代码][代码] [代码][代码]* 生命周期函数--监听页面卸载[代码][代码] [代码][代码]*/[代码][代码] [代码][代码]onUnload: [代码][代码]function[代码] [代码]() {[代码] [代码] [代码][代码]},[代码] [代码] [代码][代码]/**[代码][代码] [代码][代码]* 页面相关事件处理函数--监听用户下拉动作[代码][代码] [代码][代码]*/[代码][代码] [代码][代码]onPullDownRefresh: [代码][代码]function[代码] [代码]() {[代码] [代码] [代码][代码]},[代码] [代码] [代码][代码]/**[代码][代码] [代码][代码]* 页面上拉触底事件的处理函数[代码][代码] [代码][代码]*/[代码][代码] [代码][代码]onReachBottom: [代码][代码]function[代码] [代码]() {[代码] [代码] [代码][代码]},[代码] [代码] [代码][代码]/**[代码][代码] [代码][代码]* 用户点击右上角分享[代码][代码] [代码][代码]*/[代码][代码] [代码][代码]onShareAppMessage: [代码][代码]function[代码] [代码]() {[代码] [代码] [代码][代码]}[代码][代码]})[代码]
2019-11-28