main.ts中注册
import { createSSRApp } from "vue";
import App from "./App.vue";
//@ts-ignore
import GlobalMessage from "@/componets/GlobalMessage/GlobalMessage.js";
function registerGlobal(app) {
app.config.globalProperties.$myMethod = function () {
console.log('This is my method.')
}
app.use(GlobalMessage);
console.error("全局", app)
}
export function createApp() {
const app = createSSRApp(App);
registerGlobal(app);
return {
app,
};
}
使用
console.log("myMethod()", $myMethod())
报错
$myMethod is not defined
0 个回复