1,在入口文件main.js中注册全局属性,注册方式如下:
const app = createApp(App)
app.config.globalProperties.$Api = Api;
2,在需要的地方调用方法如下:
import { defineComponent, reactive, ref, getCurrentInstance } from "vue";
const { ctx } = getCurrentInstance();
// 调用示例
ctx.$Api.user.add(ruleForm).then((res) => {})
官方文档示例