Ionic 3技术汇总

自定义类或函数的使用

2018-07-20  本文已影响0人  IT飞牛

在ionic3项目根目录下新建一个文件:appconfig.ts,代码如下:

export class AppConfig {
    //测试环境URL
    public static getDebugUrl() {
        return "http://localhost:8080";
    }
    //生产环境URL
    public static getProdUrl() {
        return "http://service:8080";
    }
    //获取设备高度
    public static getWindowHeight() {
        return window.screen.height;
    }
    //获取设备宽度
    public getWindowWidth() {
        return window.screen.width;
    }
}

在使用的页面需要引入

import { AppConfig } from './../appconfig';

constructor(public appconfig: AppConfig) {
//静态方法使用
console.log(AppConfig.getWindowHeight())
//普通方法使用
console.log(this.appconfig.getWindowWidth())
  }
上一篇 下一篇

猜你喜欢

热点阅读