我想把 this.a2 的排序倒过来,为何我下面这么写出现报错?TypeError: _this.a2.reverse is not a function
<template> <view>
<view v-for="(item,index) in a2 " class="box1" :key="index">
<view :style="item.l11_30==true?'background-color:#FFB9DC':'background-color:#CCCCCC'">
<view class="box2"><text Selection space="ensp">借用时间:{{item.l11_4}} text>view>
<view class="box3"><text Selection space="ensp">记单人:{{item.l11_14}}text>view>
<view class="box2"><text Selection space="ensp">借用人:{{item.l11_10}} text>view>
<view class="box3"><text Selection space="ensp">借用教室:{{item.l11_11}}text>view>
<view class="box2"><text Selection space="ensp">借用周:{{item.l11_17}} text>view>
<view class="box3"><text Selection space="ensp">借用星期:{{item.l11_15}}text>view>
<view class="box2"><text Selection space="ensp">借用课次:{{item.l11_18}} text>view>
<view class="box3"><text Selection space="ensp">借用时间段:{{item.l11_12}}text>view>
<view class="box2"><text Selection space="ensp">备注:{{item.l11_8}} text>view>
view>
view>
view>
template>
<script>
export default {
data(){
return{
a2:[],
a3:[],
page:1,
}
},
methods:{ // methods包裹函数
getData(){
//开始请求服务器数据开始
uni.request({
url:'http://localhost/app/1.asp',
data: {
id1:'2',
id2:'addoil',
page:this.page,
},
method: 'post',
header: {
'content-type': 'application/x-www-form-urlencoded',
},
success: (res) => {
this.a2={...this.a2,...res.data},
this.a2=this.a2.reverse()
}
})
//开始请求服务器数据结束
},
// 触底的事件
onReachBottom() {
console.log('到底了')
this.page ++ // 让页码值自增 +1
this.getData() //调用加载数据方法
//this.queryObj.pagenum += 1
},
// 监听页面加载
onShow: function() {
this.getData() //调用加载数据方法
},
//下拉刷新
onPullDownRefresh() {
console.log('下拉了'),
this.a2=[],
this.page=1,
this.getData() //调用加载数据方法
}
}
}
script>
_this.a2.reverse is not a function 以后这种错误你只需要去排查 this.a2 . 因为他没有 reverse 这个方法。。。 看看this.a2 数据什么样子 是不是 数组。
然后我看你代码 this.a2={...this.a2,...res.data}, 这里已经是错误的 ,建议你去学习一下解构。 this.a2=[...this.a2,...res.data], 这样写才对。然后要注意 res.data是不是数组
a2不应该是数组吗
知道问题所致了,我后端把res.data输出为对象了。我转换成数组就可以了。谢谢大家!