Skip to content
On this page

Class: Resource

资源管理和加载
默认提供了几个常用的加载器

ts
Resource.load('photo.png');

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Resource()

Properties

listGroup

listGroup: string[] | [string, string] = []

Defined in

src/core/resource/Resource.ts:124


cache

Static cache: Object = {}

所有缓存资源

Index signature

▪ [props: string]: IRes

Defined in

src/core/resource/Resource.ts:47


loader

Static loader: LoaderType = {}

所有加载器

Defined in

src/core/resource/Resource.ts:42


nameCache

Static nameCache: Object = {}

资源别名缓存

Index signature

▪ [props: string]: string

Defined in

src/core/resource/Resource.ts:52

Methods

get

Static get(name): IRes

根据配置的名称获取资源

Parameters

NameType
namestring

Returns

IRes

Defined in

src/core/resource/Resource.ts:102


getLoader

Static getLoader(type): ILoader

获取加载器

Parameters

NameTypeDescription
typestring根据类型获取加载器

Returns

ILoader

Defined in

src/core/resource/Resource.ts:143


load

Static load(source, options?): Promise<IRes>

加载资源

Parameters

NameTypeDescription
sourcestring资源路径
options?LoadOptions配置

Returns

Promise<IRes>

Defined in

src/core/resource/Resource.ts:69


loadGroup

Static loadGroup(list, worker?): EventEmitter<ValueOf<{ COMPLATE: "complate" = 'complate'; LOADED: "loaded" = 'loaded' }>, any>

加载一组资源

Parameters

NameTypeDefault valueDescription
listLoadResListConfigundefined要加载的资源列表
workernumber1最大同时加载数量,最小为1

Returns

EventEmitter<ValueOf<{ COMPLATE: "complate" = 'complate'; LOADED: "loaded" = 'loaded' }>, any>

Defined in

src/core/resource/Resource.ts:131


set

Static set(name, url): boolean

配置资源别名

Parameters

NameTypeDescription
namestring别名
urlstring资源url

Returns

boolean

Defined in

src/core/resource/Resource.ts:115


setLoader

Static setLoader(type, loader): void

添加/修改一个loader加载器

Parameters

NameTypeDescription
typestring类型
loaderILoader加载器

Returns

void

Defined in

src/core/resource/Resource.ts:59