Template syntax
์ธํ๋ฐ Vue.js ์์ํ๊ธฐ - Age of Vue / ์ฅ๊ธฐํจ(์บกํดํ๊ต)
Watch ์์ฑ
data์ ๋ณํ๊ฐ ์์ ๋ ํน์ ๋ก์ง์ ์คํํ๋ ์์ฑ
watch: {
//newValue:๊ฐฑ์ ๋ ๊ฐ, oldValue:์ด์ ๊ฐ
//data ๋ณํ๋ฅผ ๊ณ์ ์ถ์ ํ๊ธฐ ๋๋ฌธ์ ์ด์ ๊ฐ๊ณผ ๊ฐฑ์ ๋ ๊ฐ ๋ชจ๋ ๋ฐ์ ์ ์์
data: function(newValue, oldValue) {
์คํ ํ ๋ก์ง;
}
}
Watch vs Computed
๋๋๋ก์ด๋ฉด computed๋ฅผ ์ฐ๋๊ฒ ์ข๊ณ watch๋ณด๋ค๋ computed๊ฐ ๋๋ถ๋ถ์ ์ผ์ด์ค์ ์ ํฉ. computed๋ก ํ ์ ์๋ ์ผ์ watch๋ก ํ ํ์ ์์
Computed์ Watch ๋น๊ต ๊ณต์๋ฌธ์
Computed
๋ทฐ ๋ด๋ถ์ ์ผ๋ก ๊ณ์ฐ์ ํ๋ ์์ฑ
๋ฐ์ดํฐ ์์กด์ฑ
๋น ๋ฅธ ๊ณ์ฐ, ๋จ์ ๊ณ์ฐ
validation, ๊ฐ๋จํ ํ ์คํธ ์ฐ์ฐ
computed: {
errorTextColor: function() {
//์ผํญ ์ฐ์ฐ์
return this.isError ? 'warning' : null;
}
}
Watch
๋ฌด๊ฑฐ์ด ๋ก์ง, ๋งค๋ฒ ์คํ๋๊ธฐ ๋ถ๋ด๋๋ ๋ก์ง
๋ฐ์ดํฐ ์์ฒญ
method๋ฅผ ์ฎ์ด์
Last updated