在 Vue2 中,我能够访问我的 Vue 实例以使用在 Vue 中注册的组件。
测试.js
import Vue from 'vue'
export function renderLogin () {
Vue.toasted.show('Please login again', { type: 'error', duration: 2000 })
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,我能够访问 toasted 包,因为我已经在 main.js 中使用 Vue 注册了它。但是,在 Vue3 中,我无法使用 toasted 包,因为我无法访问 js 文件内的 Vue 实例。
需要有关如何访问 js 文件中的 Vue 实例('this') 的帮助。