Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue - global import

I use

import {mapFields} from "vuex-map-fields"

in every component.

How can I make this available in every component without having to import it? Is there any risk to this?

like image 863
AlexanderDavidson Avatar asked Dec 24 '22 02:12

AlexanderDavidson


1 Answers

if you want it globally what you have to do it's inject in the Vue instance same way that we do when we use vuex

main.js

import Vue from 'vue'
import store from './store'

new Vue( {
  el: '#app',
  store,
  render: h => h( App )
} );

then in any component you can console.log(this); you should be able to see your object

like image 159
Marcogomesr Avatar answered Jan 05 '23 10:01

Marcogomesr