2***@qq.com
2***@qq.com
  • 发布:2023-05-22 10:29
  • 更新:2023-05-22 10:29
  • 阅读:262

uniapp 3.x版本+ts+vite,全局挂载属性和方法,使用报is not defined

分类:uni-app

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
2023-05-22 10:29 负责人:无 分享
已邀请:

要回复问题请先登录注册