Vue.js - Making helper functions globally available to single-file components

前端 未结 7 1826
北荒
北荒 2020-12-07 18:38

I have a Vue 2 project that has many (50+) single-file components. I use Vue-Router for routing and Vuex for state.

There is a file, called helpers.js

相关标签:
7条回答
  • 2020-12-07 19:36

    Import it in the main.js file just like 'store' and you can access it in all the components.

    import Vue from 'vue'
    import App from './App'
    import router from './router'
    import store from './store'
    
    Vue.config.productionTip = false
    
    /* eslint-disable no-new */
    new Vue({
      el: '#app',
      store,
      router,
      render: h => h(App)
    })
    
    0 讨论(0)
提交回复
热议问题