Vue

Methods

  • λ‚΄λΆ€μ μœΌλ‘œ μ‚¬μš©κ°€λŠ₯ν•œ ν•¨μˆ˜λ“€μ„ λͺ¨μ•„λ†“λŠ”λ‹€.
export default {
  data() {
    value = null
  },
  methods: {
    /* λ‚΄λΆ€ ν•¨μˆ˜λͺ©μ μœΌλ‘œ 주둜 μ‚¬μš© */
  }
}

Computed

  • λ‚΄λΆ€ μΊμ‹œλ₯Ό μ‚¬μš©ν•˜κΈ° λ•Œλ¬Έμ— κ³„μ‚°λœ μ†μ„±λ§Œ μ‚¬μš©ν•˜λŠ”κ²ƒμ„ μΆ”μ²œν•œλ‹€.
  • Getter 속성 λͺ©μ μœΌλ‘œλ§Œ μ‚¬μš©ν•˜λ©° ν•„μš”μ— μ˜ν•΄μ„œλŠ” Setter μ‚¬μš©μ΄ κ°€λŠ₯ν•˜λ‹€.
export default {
  data() {
    return {
      value: ''
    };
  },
  computed: {
    getValue: {
      get: () => this.value,
      set: value => this.value = value
    }
  }
}

Watch

  • λ³€μˆ˜κ°€ λ³€κ²½λ˜λŠ”κ²ƒμ„ κ°μ§€ν•˜μ—¬ 이전값과 μƒˆλ‘œμš΄ 값을 μ œκ³΅ν•œλ‹€.
  • 일반적인 λ³€μˆ˜λ₯Ό ν¬ν•¨ν•˜μ—¬ computed ν•¨μˆ˜ μ„ μ–Έκ³Ό λ™μ‹œμ— μ‚¬μš©κ°€λŠ₯ν•˜λ‹€.
export default {
  data() {
    return {
      value: ''
    };
  },
  computed: {
    getValue: {
      get: () => this.value,
      set: value => this.value = value
    }
  },
  /* λ³€μˆ˜κ°€ λ³€κ²½λ˜λŠ” 것을 감지 */
  watch: {
    getValue(newValue, oldValue) {
      console.log('μƒˆλ‘œμš΄ κ°’ : ' + newValue);
      console.log('였래된 κ°’ : ' + oldValue);
    }
  }
}