@18ys/god 中文文档教程

发布于 4年前 浏览 26 项目主页 更新于 3年前

What is God?

god是一个全局的target,可以给它设置一些数据,解决vue3没有全局的vue。

Installation

Node.js

$ npm install @18ys/god

Module

umd

Usage

import { give, ask, clean } from '@18ys/god';

// for example: set axios instance to god

// give one time at a file with js
let instance = axios.createInstance();
give('axios', instance, { readonly: true });

// use Infinity times at any file with js
let axiosInstance = ask('axios');
axiosInstance.get('http://example.com/getData').then(..)

// when you couldn't use some keys, clean it.
clean('axios');
ask('axios'); // null

Api

import god from '@18ys/god';

// 1. set
god.give(key: string, value: any, options?: { readonly?: boolean });
// readonly default is false, when you set readonly as true, the key is can't be cleaned

// 2. get
god.ask(key: string) // return (value: any | null)

// 3. remove
god.clean(key: string)

What is God?

God is a global target, you can set some data to it, to resolve that vue3 don't have the global Vue.

Installation

Node.js

$ npm install @18ys/god

Module

umd

Usage

import { give, ask, clean } from '@18ys/god';

// for example: set axios instance to god

// give one time at a file with js
let instance = axios.createInstance();
give('axios', instance, { readonly: true });

// use Infinity times at any file with js
let axiosInstance = ask('axios');
axiosInstance.get('http://example.com/getData').then(..)

// when you couldn't use some keys, clean it.
clean('axios');
ask('axios'); // null

Api

import god from '@18ys/god';

// 1. set
god.give(key: string, value: any, options?: { readonly?: boolean });
// readonly default is false, when you set readonly as true, the key is can't be cleaned

// 2. get
god.ask(key: string) // return (value: any | null)

// 3. remove
god.clean(key: string)
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文