Skip to content

公共

封装

window.nxhSDK

ts
declare const nxhSDK: {
  init: typeof init; // 初始化
  useSDKStore: typeof useSDKStore;
  storeKey: symbol;
};

window.nxhSDKLib

ts
declare const nxhSDKLib: {
  storage: {}; //storage
  common: {}; //基于uniapp封装的方法
  cookie: {}; //cookie
  user: {}; //用户接口
  $init: {}; //页面初始化方法
  $post: {}; //请求方法
  share: {}; //分享数据
};

初始化

ts
// 初始化 main.js
import { nxhSDK } from "@/nxhsdk.module.min";
nxhSDK.init({ uniApp: App, ssrApp: app });

// 使用封装好的公共数据
import { nxhSDK, nxhSDKLib } from "@/nxhsdk.module.min";
const store = nxhSDK.useSDKStore();

// 使用封装好的公共方法
import { nxhSDK, nxhSDKLib } from "@/nxhsdk.module.min";
const oCommon = nxhSDKLib.common;
oCommon.isWechat();

// 页面初始化
import { nxhSDKLib } from "@/nxhsdk.module.min";
nxhSDKLib.$init(() => {
  console.log("页面初始化");
});

// 同理可使用user、cookie、storage、$post、share等方法

获取数据

MODULE_NAME 是模块的名称,详细见各个模块

ts
function getData<ModuleData>(
  module: String,
  params?: ? extends ModuleParams
): Promise<ModuleData> {}

// 使用范例
import { nxhSDK} from "@/nxhsdk.module.min";

nxhSDK.getData("MODULE_NAME", params).then((resp) => {
  console.log(resp);
});