Open martinwithyou opened 4 years ago
优化点一: 可以使用 async await 简化代码
优化点二: 可以使用 简化 数据结构 const data = response.data 简化代码
// 数据初始化 _initData async () { const response = await getHomeData(); if (response.success) { const data = response.data // 给轮播组件 sowing_list赋值 this.sowing_list = data.list[0].icon_list; this.nav_list = data.list[2].icon_list; this.flash_sale_product_list = data.list[3].product_list; this.tabbar_all_product_list = data.list[12].product_list; this.isShowLoading = false // 给特色专区赋值 this.specialZone = data.special_zone; // 获取首页广告图 this.home_ad = data.home_ad.image_url; } }
DuZhu: Right! Thanks a lot give me the code improve suggest.You can send pull requests for me.We maintain together.Thanks you~😁