2017-12-31 53 views

답변

3

당신이하고있는 것을 보지 않고서 당신이 달성하고자하는 것을 정확히 아는 것은 어렵습니다. 일반적으로 사용자가 직접 watchers을 처리해서는 안되므로 더 나은 솔루션이 있는지 코드를 살펴볼 필요가 있습니다.

new Vue({ 
    el: '#app', 
    created() { 
    // this won't fire the watcher as it hasn't been applied yet 
    this.foo = 'foo' 
    }, 
    mounted() { 
    // Apply watcher after all other initialization is done 
    this.applyFooWatcher() 
    }, 
    methods: { 
    applyFooWatcher() { 
     this.$watch('foo', function(newVal, oldVal) { 
     console.log('Foo changed from ' + oldVal + ' to ' + newVal); 
     }); 
    } 
    }, 
    data: { 
    foo: '' 
    } 
}) 
다음

년대 JSFiddle : https://jsfiddle.net/fo0vmxf6/

그렇게 말한다면, 당신이 다른 initialised 모든 것을 가지고 한 후, 당신은 mounted 후크 내부에 그것을 할 수하는 watcher 런타임에 적용하는 것이 가능하다
관련 문제