通过hbuliderx在微信小程序运行发送的错误 在uniapp和H5端都好使 放在微信小程序端就不行 找了一天,人都麻了
uniapp好使的代码:
<button @click="getmoreworks()">查看全部
getmoreworks() {
uni.request({
url: this.global.baseUrl + '/story/getWorks',
data: {},
success: (res) => {
console.log(res.data.data)
this.authorlist = []
for (let i = 1; i < 30000; i++) {
this.y = []
this.y.storyId = res.data.data[i].id
this.y.player1 = res.data.data[i].userOneId
this.y.player2 = res.data.data[i].userTwoId
this.authorlist.push(this.y)
}
},
fail: (res) => {
this.globalmethods.errorMsg('test', uni.getStorageSync('playerId'))
}
})
},
通过hbuliderx编译为wx语言不好使的代码为:
<button data-event-opts="{{[['tap',[['getmoreworks']]]]}}" bindtap="__e">查看全部</button>
getmoreworks: function getmoreworks() {var _this3 = this;
uni.request({
url: this.global.baseUrl + '/story/getWorks',
data: {},
success: function success(res) {
console.log(res.data.data);
_this3.authorlist = [];
for (var i = 1; i < 30000; i++) {
_this3.y = [];
_this3.y.storyId = res.data.data[i].id;
_this3.y.player1 = res.data.data[i].userOneId;
_this3.y.player2 = res.data.data[i].userTwoId;
_this3.authorlist.push(_this3.y);
}
},
fail: function fail(res) {
_this3.globalmethods.errorMsg('test', uni.getStorageSync('playerId'));
} });
},
(不是没转JSON)
console.log(res.data.data);在wx打印结果是正常的 为:
现在显示的不正常
题主将源代码getmoreworks中改this.y = []为this.y = {},然后再重新编译
而且for循环越界了,才2个键值
for (let i = 1; i < 30000; i++) {
改为
for(let i of Object.keys(res.data.data))
遍历返回键
但是uniapp居于vue的,vue 2测试了浏览器是正常的,可以用[]替代{},小程序可能做了什么什么限制
id 未定义 res.data.data[i] 里没有id 你打印一下看看 。 你这个for循环 有问题 i<3才行 。 你data 最大长度才2 。
会不会是因为引入的h5使用的插件依赖而小程序不支持所以报错
https://blog.csdn.net/ys_healone/article/details/121692178
for (let key in res.data.data) {
this.authorlist.push({
storyId: res.data.data[key].id,
player1: res.data.data[key].userOneId,
player2: res.data.data[key].userTwoId,
});
}
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!