2016-08-26 2 views
1

나는 간단한 코드 나는 단지 requrie 폭동, test.tag 내 app.js에폭동 JS this.update 이상한 행동

<test> 
<ul> 
    <li each={ books }> { title }</li> 
</ul> 

<button type="button" name="button" onclick={ loadBooks }>Load books</button> 

<script> 
    'use strict'; 

    this.books = []; 
    let offset = 0; 

    this.on('mount',() => { 
    console.log('mounted'); 
    }); 

    this.on('update',() => { 
    console.log('updated'); 
    }); 

    loadBooks() { 
    fetch('/api/books?limit=10&offset='+offset) 
    .then(response => response.json()) 
    .then(books => { 
     offset+=10; 
     this.books = books; 
     // this.update(); 
    }) 
    .catch(err => console.log(err)); 
    } 
</script> 

을 가지고 riot.mount('#root', 'test'); 이가 초기화 화면, 왜 업데이 트를 할 마운트 전에 해고 됐어? 내가 처음 클릭하면 enter image description here , 그 업데이트가 해고 그러나보기 enter image description here 을 다시 렌더링하지 않고 두 번째 클릭 후, 이벤트 업데이트를 해고하고 난 내 this.update(); 주석을 제거하면보기 enter image description here enter image description here

다시는 렌더링 로그인 약속, 이벤트 업데이트가 두 번 해지됩니다.

업데이트 : this.books = books을 제거하고 this.update({books}); 이벤트 업데이트를 실행하면 렌더링이 작동하지만 렌더링이 작동하지만 왜 2 번입니까?

+0

js를 두 번 포함 시켰습니까? 때로는 두 번 처리되는 이벤트의 원인입니다 –

+0

아니, 1 번 번들 파일이 포함되어 있습니다. –

답변