当前位置:网站首页>Using computed in uni app solves the abnormal display of data () value in tab switching
Using computed in uni app solves the abnormal display of data () value in tab switching
2022-07-02 14:08:00 【Web front end typist】
tab After switching, the data display is abnormal
The data structure returned by the back end =>
{
“status”:1,
“msg”:“ The query is successful ”,
“data”:{
“no_start_work_count”:1,
“working_count”:0,
“in_working_count”:0,
“work_end_count”:0,
“work_over_dd_count”:0,
“work_over_count”:0,
“count”:1,
“pageCount”:1,
“nowPage”:“1”,
“list”:[
{
“id”:137,
“work_sn”:“gd16562977xxx8”,
“user_id”:6718xx,
“type”:2,
“address”:“ Guangdong province, guangzhou XXX XXX”,
“phone_mob”:“13488888888”,
“consignee”:“wwater”,
“image_url”:“”,
“remark”:“ Looking forward to the door-to-door time :2022-06-27 10:41-10:38;<br/> Work order requirements : This is whether the test time can be checked ”,
“add_time”:“2022-06-27 10:42”,
“visit_time”:“2022-06-27 10:41”,
“order_id”:194956xxx,
“order_sn”:“20220627104xxxxxx”,
“recs_id”:“4443xxx”,
“status”:2,
“worker_profit_money”:“0.00”,
“items_that”:“ Wall mounted ”,
“punch”:1,
“fault_num”:1,
“fault_type”:2,
“fault_money”:“10.00”,
“orderGoods”:{
“goodsList”:[
{
“goods_name”:“ Washing machine installation ”,
“goods_image”:“https://oss.aliyuncs.com/tpsite2/zuolinyouli.xyd.qushiyun.com/8af4ccf9ccb7554c0af684de201faf66.png”,
“price”:“0.01”,
“quantity”:“1.00”
}
],
“orderPrice”:“0.01”
},
“lng”:null,
“lat”:null,
“distance”:0,
“status_text”:“ Dispatched ”,
“user_avatar”:“https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83eqZ4vmXhgRLao1iamtR114XPyADIF9UV9nEibndUudcPiaFVQlibibn6rd4HJ06zH3THmvEC6I3dNSZvdA/132”
}
]
}
}
BUG View and analysis
adopt axios The obtained data will be rendered and bound later , My side
Code =>
adopt map Traverse the loop and return the product name and quantity , However, the above situation will occur in the switching process goodsQuantity``goodsName
Turn into object object .
What the label shows
<view class="left text_overflow padding20">{
{goodsName}}x{
{goodsQuantity}}</view>
data() {
return {
goodsName:"",
goodsQuantity:0,
orderList:[],
}
},
methods:{
getDetail() {
let that = this
let url = Address interface
let datakey = []
// ......datakey Parameters to be passed
// datakey['limit'] = 10
Util.request(url, datakey, "GET", res => {
// .......
let orderList = res.data.list
this.orderList = [...this.orderList, ...orderList];
this.status = 'loadmore'
// Here is the assignment operation
that.goodsName = orderList.orderGoods.goodsList.map(item =>{
return item.goods_name
})
that.goodsQuantity = orderList.orderGoods.goodsList.map(item =>{
return item.quantity
})
if (orderList.length < 10) {
this.switch = true
this.status = 'nomore'
}
}, err => {
console.error(err)
})
},
}
resolvent
By calculating properties computed
To solve this problem :
difference data and computed
data and computed The core difference is data The properties in do not change with the change of the assigned variable , and computed Meeting .( Assignment variables are similar :num: aaa.bbb, The direct assignment is num: 123); That is, if our value is variable , Then use this computed To use ,computed You can more finely control attribute reading and writing , But it needs a temporary variable (temp_name) Can achieve .
<view class="left text_overflow padding20">{
{shopGoodsName }}x{
{shopGoodsQuantity}}</view>
data() {
return {
goodsName:"",
goodsQuantity:0,
orderList:[],
}
},
computed:{
shopGoodsName() {
return this.goodsName = this.orderList.map(val =>{
return val.orderGoods.goodsList.map(item =>{
return item.goods_name
})
})
},
shopGoodsQuantity() {
return this.goodsQuantity = this.orderList.map(val =>{
return val.orderGoods.goodsList.map(item =>{
return parseInt(item.quantity)
})
})
}
},
methods:{
getDetail() {
let that = this
let url = Address interface
let datakey = []
// ......datakey Parameters to be passed
// datakey['limit'] = 10
Util.request(url, datakey, "GET", res => {
// .......
let orderList = res.data.list
this.orderList = [...this.orderList, ...orderList];
this.status = 'loadmore'
if (orderList.length < 10) {
this.switch = true
this.status = 'nomore'
}
}, err => {
console.error(err)
})
},
}
It finally solved the problem
边栏推荐
- Which do you choose between Alibaba P7 with an annual salary of 900000 and deputy department level cadres?
- Qt新建项目
- Halcon extract orange (Orange)
- 大家信夫一站式信用平台让信用场景“用起来
- [technology development-22]: rapid overview of the application and development of network and communication technology-2-communication Technology
- selenium 在pycharm中安装selenium
- Sum of the first n terms of Fibonacci (fast power of matrix)
- selenium的特点
- SystemServer进程
- 693. 行程排序(map + 拓扑)
猜你喜欢
A better database client management tool than Navicat
Default slot, named slot, scope slot
万物生长大会在杭召开,当贝入选2022中国未来独角兽TOP100榜单
默认插槽,具名插槽,作用域插槽
当贝投影4K激光投影X3 Pro获得一致好评:万元投影仪首选
Qt新项目_MyNotepad++
Find love for speed in F1 delta time Grand Prix
kaggle如何使用utility script
Whole house Wi Fi: a pain point that no one can solve?
Qt新建项目
随机推荐
大家信夫一站式信用平台让信用场景“用起来
Don't spend money, spend an hour to build your own blog website
Qt-制作一个简单的计算器-实现四则运算
每日学习3
[USACO05JAN]Watchcow S(欧拉回路)
OpenFOAM:lduMatrix&lduAddressing
[Blue Bridge Cup] children's worship circle
Mysql5.7 installation super easy tutorial
无主灯设计:如何让智能照明更加「智能」?
D language, possible 'string plug-ins'
Start to write a small demo - three piece chess
Slashgear shares 2021 life changing technology products, which are somewhat unexpected
Use of UIC in QT
Which do you choose between Alibaba P7 with an annual salary of 900000 and deputy department level cadres?
Quarkus学习四 - 项目开发到部署
石子合并板子【区间DP】(普通石子合并 & 环形石子合并)
Add sequence number column to query results in MySQL
数据湖(十一):Iceberg表数据组织与查询
混沌工程平台 ChaosBlade-Box 新版重磅发布
Astro learning notes