2017-05-23 1 views
0

기본적으로 내 선택 드롭 다운에 루프가있어 데이터를 올바르게 표시합니다.부트 스트랩 선택이 초기화 될 때 Vue 루프가 작동하지 않습니다.

<select name="" id="input" class="form-control selectteam"> 
    <option value="" disabled="" selected="">Filter by team</option> 
    <option v-for="(team, index) in nblTeams" :value="team.clubName">{{team.clubName}}</option> 
</select> 

하지만 난) ($ ('selectteam.') selectpicker를 추가 할 때.;

mounted: function() { 
     this.getCurrentSeasonTeams().then((response) => { 
      if(response.status == 200 && typeof(response.data) == 'object') { 
       this.nblTeams = response.data; 
      } 
     }); 

     $('.selectteam').selectpicker(); 
    } 

아래 코드에 따라, 장착 방법는 이미 팀의 목록을 표시 나던. Btw 사용하고 있습니다 bootstrap-select - Silvio Moreto

+0

jQuery를 어디에서 실행하고 있습니까? 코드의 해당 부분을 공유 할 수 있습니까? – ricopo

+0

@ricopo laravel 5.4를 사용하고 있습니다. 그래서 bootstrap.js에서 jQuery가 필요했고 Vue 마운트 메소드에서 bootstrap-select를 초기화 할 곳이 있습니다. – PenAndPapers

답변

1

nextTick을 사용해 보셨습니까? VUE 시계의 다음 틱에 bootstrapselect init을

VUE docs, next-tick

mounted: function() { 
    this.getCurrentSeasonTeams().then((response) => { 
     if(response.status == 200 && typeof(response.data) == 'object') { 
      this.nblTeams = response.data; 
     } 
    }); 

    this.$nextTick(function(){ 
     $('.selectteam').selectpicker(); 
    }); 
} 

는 편집 : 경우

mounted: function() { 
    this.getCurrentSeasonTeams().then((response) => { 
     if(response.status == 200 && typeof(response.data) == 'object') { 
      this.nblTeams = response.data; 

      this.$nextTick(function(){ 
       $('.selectteam').selectpicker(); 
      }); 
     } 
    }); 
} 
+0

해결책을 시도했지만 작동하지 않습니다. – PenAndPapers

+0

콘솔 오류가 발생합니까? –

+0

콘솔 오류가 없습니다 @ Taufik Akbar, 방금 해결했다고 생각합니다. – PenAndPapers

0

정말 확실하지 내가 만든 한 내용을 내 문제에 대한 좋은 해결책입니다. setTimeout 메서드를 추가하면 작동합니다.

this.getCurrentSeasonTeams().then((response) => { 
     if(response.status == 200 && typeof(response.data) == 'object') { 
      this.nblTeams = response.data; 
      if(typeof(this.nblTeams) == 'object'){ 
       setTimeout(() => { 
        $('.team').selectpicker(); 
       }, 500); 
      } 
     } 
    }); 
+0

그리고 settimeout이 없으면 작동하지 않습니다. – ricopo

+0

@ricopo 예 그것은 작동하도록 setTimeout이 필요합니다, 나는 bootstrap-select가 선택 상자를 체크했을 때 DOM이로드되었을 때 선택 상자가 있는지 생각해 봅니다. 제 경우에는 루프가 아직 완성되지 않았습니다. 부트 스트랩을 선택하십시오. 왜 선택 상자에는 옵션이 없습니다. 그냥 이론 비록 – PenAndPapers

+0

@ PenAndPapers 내 편집 확인하십시오. 목록이 길면 시간 초과 방법이 실패 할 수 있습니다. –

관련 문제