How to introduce public method files encapsulated by themselves in vue-cli?

I fetched the package in main.js. Why can"t other vue components call the methods directly?

clipboard.png

clipboard.png

Mar.20,2021

.vue is to be compiled and messed around by webpack , not to mention the details.

is usually injected with plug-ins:

ide/plugins.html" rel=" nofollow noreferrer "> plug-in-- Vue.js


can be mounted on the prototype Vue.prototype.$ajax


is usually called in the form of a plug-in to install, and then. Of course, I think you can directly import {post} from'. Then mount it to the vue prototype. There is no need for install. If you want to figure out how this install is implemented, you can take a look at the loading,msg implementation under the ui framework and see how they expose the install method.


I suspect you are on the wrong path. This is also a project built by vue-cli. Isn't it . / utils/http that you were introduced into your file path from main.js.

// main.js
import { post } from './utils/http'
Vue.prototype.$post = post

//  ok
this.$post(xxxxxxxx)
Menu