请问这个怎么优化?

3131975015
  • 591
    let currentList = []
    if(this.data.currentTab == 0){
        currentList = this.data.list1
    }
    if(this.data.currentTab == 1){
      currentList = this.data.list2
    }
    if(this.data.currentTab == 2){
      currentList = this.data.list3
    }
    if(this.data.currentTab == 3){
      currentList = this.data.list4
    }
    if(this.data.currentTab == 4){
      currentList = this.data.list5
    }
回复
阅读 617
2 个回答

let currentList = this.data['list' + (this.data.currentTab + 1)] || []

let props = ['list1', 'list2', 'list3', 'list4', 'list5']

let currentList = this.data[props[this.data.currentTab]] || []
宣传栏