官术网_书友最值得收藏!

Service without dependencies

A service without dependencies is a service whose constructor is empty:

export Service {
constructor(){}
getData() {}
}

To use it, you simply type:

import { Service } from './service'
let service = new Service();
service.getData();

Any module that consumes this service will get their own copy of the code, with this kind of code. If you, however, want consumers to share a common instance, you change the service module definition slightly to this:

class Service {
constructor() {}
getData() {}
}
const service = new Service();
export default service;

Here, we export an instance of the service rather than the service declaration. 

主站蜘蛛池模板: 泰兴市| 安远县| 道真| 福建省| 环江| 集贤县| 江山市| 孟村| 秀山| 易门县| 调兵山市| 汝州市| 蒙阴县| 沁水县| 图片| 岚皋县| 中方县| 海城市| 德安县| 化德县| 山丹县| 阳信县| 乌兰浩特市| 辽阳市| 马尔康县| 垣曲县| 梁平县| 乌兰浩特市| 蒙自县| 乌兰察布市| 德阳市| 香港| 曲松县| 深泽县| 瓦房店市| 柘荣县| 华容县| 新和县| 卓资县| 繁峙县| 香河县|