Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用 async await 简化代码 #19

Open
martinwithyou opened this issue Dec 10, 2019 · 2 comments
Open

使用 async await 简化代码 #19

martinwithyou opened this issue Dec 10, 2019 · 2 comments
Labels
improve improve

Comments

@martinwithyou
Copy link
Contributor

// 数据初始化
_initData () {
  getHomeData().then(response => {
    if (response.success) {
      // 给轮播组件 sowing_list赋值
      this.sowing_list = response.data.list[0].icon_list;
      this.nav_list = response.data.list[2].icon_list;
      this.flash_sale_product_list = response.data.list[3].product_list;
      this.tabbar_all_product_list = response.data.list[12].product_list;
      this.isShowLoading = false
      // 给特色专区赋值
      this.specialZone = response.data.special_zone;
      // 获取首页广告图
      this.home_ad = response.data.home_ad.image_url;
    }
  }).catch(error => {
    console.log(error);
  });
@martinwithyou
Copy link
Contributor Author

martinwithyou commented Dec 10, 2019

优化点一:
可以使用 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;
}
}

@Geek-James
Copy link
Owner

DuZhu:
Right! Thanks a lot give me the code improve suggest.You can send pull requests for me.We maintain together.Thanks you~😁

@Geek-James Geek-James added the improve improve label Dec 10, 2019
@martinwithyou martinwithyou changed the title 代码优化 使用 async await 简化代码 Dec 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improve improve
Projects
None yet
Development

No branches or pull requests

2 participants