Webpack+vue single page application registration global js

I wrote a js file myself in the following format

import axios from "axios"
import env from "../../config/env"
import Vue from "vue"
import router from "../router"

axios.defaults.withCredentials = true

export default {
  ...
}

then import u from"@ / libs/u.js", in every vue file feels redundant
how to register this variable u directly to the global, you can directly use the method in the js file in vue without import

Mar.11,2021

Global call to
where plug-ins can be written in

webpack can also be mounted in the prototype of vue
or mounted on window

clipboard.png

it can be changed to a path


ide/plugins.html" rel=" nofollow noreferrer "> vue plugin to learn


import Vue from 'vue'
import u from '@/libs/u.js'

Vue.prototype.$u = u;

//
this.$u();

the most concise, direct and effective way: quote your js directly through script in index.html

Menu