Post

[Vue] Vue3 global(전역) 함수 사용하기

[Vue] Vue3 global(전역) 함수 사용하기

1. JS 파일 생성

1
2
3
4
5
6
7
8
9
10
11
const methods = {
  globalFuncTest(){
    console.log('global function test');
  }
}

export default {
  install(Vue) {
    Vue.config.globalProperties.$globalFuncTest = methods.globalFuncTest;
  }
}

2. main.js 파일에서 생성한 파일 글로벌 선언하기

1
2
3
4
5
6
7
(main.js)

import globalMethods from "./assets/js/front"

createApp(App)
  .use(globalMethods)
  .mount('#app');

3. 함수 사용

1
2
3
mounted(){
  this.$globalFuncTest();
},


참고
This post is licensed under CC BY 4.0 by the author.