How do ordinary js files call the methods mounted on Vue.prototype

Sometimes in a vue project, ordinary js files need to call some public methods, but our public methods are all mounted on the vue prototype object,
insert image description here
which can be called directly in the vue file,
but calling directly in the js file will display undefined

Solution: In the js file 1. Introduce Vue 2. Instantiate Vue 3. Call the method from the prototype object

//引入vue
import Vue from "vue"
//必须实例化
var vm = new Vue()
//调用方法
vm.$getSlyTokenStatus()

insert image description here

Guess you like

Origin blog.csdn.net/weixin_42821697/article/details/123269789