Skip to content

Commit 2d800ff

Browse files
committed
변경된 예시 코드 반영
1 parent 6a898be commit 2d800ff

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

src/v2/guide/computed.md

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -214,35 +214,34 @@ var watchExampleVM = new Vue({
214214
// 질문이 변경될 때 마다 이 기능이 실행됩니다.
215215
question: function (newQuestion) {
216216
this.answer = '입력을 기다리는 중...'
217-
this.getAnswer()
217+
this.debouncedGetAnswer()
218218
}
219219
},
220-
methods: {
220+
created: function () {
221221
// _.debounce는 lodash가 제공하는 기능으로
222222
// 특히 시간이 많이 소요되는 작업을 실행할 수 있는 빈도를 제한합니다.
223223
// 이 경우, 우리는 yesno.wtf/api 에 액세스 하는 빈도를 제한하고,
224224
// 사용자가 ajax요청을 하기 전에 타이핑을 완전히 마칠 때까지 기다리길 바랍니다.
225225
// _.debounce 함수(또는 이와 유사한 _.throttle)에 대한
226226
// 자세한 내용을 보려면 https://lodash.com/docs#debounce 를 방문하세요.
227-
getAnswer: _.debounce(
228-
function () {
229-
if (this.question.indexOf('?') === -1) {
230-
this.answer = '질문에는 일반적으로 물음표가 포함 됩니다. ;-)'
231-
return
232-
}
233-
this.answer = '생각중...'
234-
var vm = this
235-
axios.get('https://yesno.wtf/api')
236-
.then(function (response) {
237-
vm.answer = _.capitalize(response.data.answer)
238-
})
239-
.catch(function (error) {
240-
vm.answer = '에러! API 요청에 오류가 있습니다. ' + error
241-
})
242-
},
243-
// 사용자가 입력을 기다리는 시간(밀리세컨드) 입니다.
244-
500
245-
)
227+
this.debouncedGetAnswer = _.debounce(this.getAnswer, 500)
228+
},
229+
methods: {
230+
getAnswer: function () {
231+
if (this.question.indexOf('?') === -1) {
232+
this.answer = '질문에는 일반적으로 물음표가 포함 됩니다. ;-)'
233+
return
234+
}
235+
this.answer = '생각중...'
236+
var vm = this
237+
axios.get('https://yesno.wtf/api')
238+
.then(function (response) {
239+
vm.answer = _.capitalize(response.data.answer)
240+
})
241+
.catch(function (error) {
242+
vm.answer = '에러! API 요청에 오류가 있습니다. ' + error
243+
})
244+
}
246245
}
247246
})
248247
</script>

0 commit comments

Comments
 (0)