Vue Plugin
ํ๋ฌ๊ทธ์ธ์ ์ผ๋ฐ์ ์ผ๋ก ์ ์ญ ์์ค ๊ธฐ๋ฅ์ vue์ ์ถ๊ฐํ๋ค
ํ๋ฌ๊ทธ์ธ ์ ํ
1.
์ ์ญ์์ ์ฌ์ฉํ๋ ๋ฉ์๋ ํน์ ์์ฑ
2.
๋๋ ํฐ๋ธ, ํํฐ, ์ ํ ํจ๊ณผ ๋ฑ
3.
์ด๋์๋ ์ ๊ทผ ๊ฐ๋ฅํ mixin
4.
์ธ์คํด์ค ๋ฉ์๋ ์ถ๊ฐ
5.
์๋ ๊ฐ์ง๊ณ ์๋ api๋ฅผ ์ ๊ณตํ๋ฉด์ ์์ ๊ธฐ๋ฅ๋ค์ ์กฐํฉํ์ฌ ์ ๊ณตํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
ํ๋ฌ๊ทธ์ธ ์ถ๊ฐ
let MyPlugin = {}
MyPlugin.install = (Vue, options) => {
// 1. ์ ์ญ์์ ์ฌ์ฉํ๋ ๋ฉ์๋ ํน์ ์์ฑ
Vue.globalMethod = () => {
...
}
// 2. ๋๋ ํฐ๋ธ, ํํฐ, ์ ํ ํจ๊ณผ ๋ฑ
Vue.directive('my-directive', {
bind (el, biding, vnode, oldVnode) {
...
}
})
// 3. ์ด๋์๋ ์ ๊ทผ ๊ฐ๋ฅํ mixin
Vue.mixin({
created () {
...
}
})
// 4. ์ธ์คํด์ค ๋ฉ์๋ ์ถ๊ฐ
Vue.prototype.$myMethod = () => {
...
}
}
export default MyPlugin
JavaScript
๋ณต์ฌ
ํ๋ฌ๊ทธ์ธ ์ ์ฉ
import myPlugin from './plugins/myPlugin'
Vue.use(myPlugin)
JavaScript
๋ณต์ฌ
์ฐธ๊ณ
โข
https://kr.vuejs.org/v2/guide/plugins.html



