2017-03-04 13 views
1

페이지가로드 될 때 <project-comp></project-comp> 구성 요소가 표시되지 않습니다. created 후크를 사용하여 projects 속성을 설정했습니다. 그러나 작동하지 않습니다. 여기 vue 구성 요소가 페이지가로드 될 때 표시되지 않습니다. 어떻게 표시합니까?

내 코드입니다 :

Vue.component('project-comp',{ 
     template: ` 
     <div class='box'>    
      <div v-for='one in this.$parent.projects'> 
       <h2> @{{one.place}}</h2> 
       <h2> @{{one.time}}</h2> 
      </div> 
     </div> 
     `, 
}); 

var app = new Vue({ 
     el: '#root', 

     props:['projects'], 

     created: function() { 
      $.post(
       'url', 
       {'city':'beijing'}, 
       function(data){ 
        this.projects = data; 
       }, 
       'json' 
      ); 
     }, 


}); 
+0

주어진 스 니펫에서는 사용하기 위해''만 등록/생성하지만 템플릿 마크 업에서는 어디에서 마운트 했습니까? – Xlee

답변

3

이것의 범위는 정확하지 않은 것, 당신은 그것을해야한다 :

: ES-6 그냥있을 수있다

var app = new Vue({ 
     el: '#root',  
     props:['projects'], 
     created: function() { 
      var self = this 
      $.post(
       'url', 
       {'city':'beijing'}, 
       function(data){ 
        self.projects = data; 
       }, 
       'json' 
      ); 
     }, 
}); 

var app = new Vue({ 
     el: '#root',  
     props:['projects'], 
     created: function() { 
      $.post(
       'url', 
       {'city':'beijing'}, 
       (data) => { 
        this.projects = data; 
       }, 
       'json' 
      ); 
     }, 
}); 

확인 this 설명을 위해.

+2

이에 대한 설명서 항목을 만들었습니다. 그것은 많이 튀어 오르는 것처럼 보입니다. http://stackoverflow.com/documentation/vue.js/9350/using-this-in-vue#t=201703042039563445243 – Bert

관련 문제