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

前端 未结 7 1830
北荒
北荒 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:11

    Great question. In my research I found vue-inject can handle this in the best way. I have many function libraries (services) kept separate from standard vue component logic handling methods. My choice is to have component methods just be delegators that call the service functions.

    https://github.com/jackmellis/vue-inject

提交回复
热议问题