Mixins

Jung taeWoongยท2021๋…„ 4์›” 1์ผ
0

vue.js

๋ชฉ๋ก ๋ณด๊ธฐ
4/9
post-thumbnail

Mixins

์—ฌ๋Ÿฌ ์ปดํฌ๋„ŒํŠธ ๊ฐ„์— ๊ณตํ†ต์œผ๋กœ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š” ๋กœ์ง, ๊ธฐ๋Šฅ๋“ค์„ ์žฌ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•
๋ฏน์Šค์ธ์— ์ •์˜ํ•  ์ˆ˜ ์žˆ๋Š” ๋กœ์ง์€ data, methods, created ๋“ฑ๊ณผ ๊ฐ™์€ ์ปดํฌ๋„ŒํŠธ ์˜ต์…˜๋“ค

mixins ์žฅ์ 

  1. ๊ณตํ†ต๋œ ๋กœ์ง์„ ๋ชจ์•„์„œ ์žฌ์‚ฌ์šฉํ•˜๊ธฐ์— ์ปดํฌ๋„ŒํŠธ ์ฝ”๋“œ๊ฐ€ ๊ฐ„๊ฒฐํ•ด์ง„๋‹ค
  2. ๋ถ€์ฐจ์ ์ธ ์š”์†Œ๋“ค(spinner, modal) mixins ์‚ฌ์šฉ์‹œ ํšจ์œจ์ด ์ข‹์Œ
  3. ์ปดํฌ๋„ŒํŠธ์—๋Š” crud์™€ ๊ด€๋ จ๋œ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง๋“ค๋งŒ ๋‚จ๊ฒŒ๋จ

HOC vs Mixcins

HOC์™€ Mixins ๋ชฉ์  ๋ชจ๋‘ ์ปดํฌ๋„ŒํŠธ์— ๋“ค์–ด๊ฐ€๋Š” ํŠน์ • ๋กœ์ง๋“ค์„ ์žฌ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ ์‚ฌ์šฉํ•จ

// mixins.js
export default {
  // ์žฌ์‚ฌ์šฉํ•  ์ปดํฌ๋„ŒํŠธ ์˜ต์…˜ & ๋กœ์ง
}

// component.vue
import mixins from '';

export default {
  mixins: [mixins], 
}



// HOC
export default function withHOC() {
  return {
 	 // ์žฌ์‚ฌ์šฉํ•  ์ปดํฌ๋„ŒํŠธ ์˜ต์…˜
    ...
    render(createElement){
      return createElement(component);
    }
  }
}

๋‹จ์ 

mixins์„ ์—ฌ๋Ÿฌ๊ฐœ๋ฅผ ์ฃผ์ž…ํ–ˆ์„ ๋•Œ๋•Œ ํŠน์ • ์ฝ”๋“œ๊ฐ€ ์–ด๋Š ๋ฏน์Šค์ธ์—์„œ ์ฃผ์ž…๋œ๊ฑด์ง€ ํ™•์ธํ•˜๊ธฐ ์–ด๋ ต๋‹ค

profile
Front-End ๐Ÿ˜ฒ

0๊ฐœ์˜ ๋Œ“๊ธ€