나는 다음과 같습니다 간단한 뷰 구성 요소가 :Vue watch에서 모델을 사용하는 방법은 무엇입니까?
export default {
data: function() {
return {
brands: [],
models: [
{id:1, name: 'one'},
{id:2, name: 'two'},
{id:3, name: 'tree'}
],
filters: {},
filter: {
brand: null,
model: null,
price: null,
year: null
}
}
},
watch: {
'filter.brand': (brand) => {
console.log('filter.brand', this, this.models)
socket.emit('brands.models.get', brand, (models) => {
console.log(models)
console.log(this.models)
this.models = models;
console.log(this.models)
})
},
}
}
가장 큰 문제는 내가 소켓에서 데이터를받을 때이 모델을 볼 수 없습니다 것입니다.
예를 들어 console.log(this.models)
은 정의되지 않은 값을 반환합니다.
여기에 전체 무엇을 인쇄하는 것은 보이는 같은 :