我正在尝试使用打字稿获取ionic 2中的设备宽度和高度。
在我以前使用的ionic 2中,
window.screen.width
window.screen.height
但在较新的版本中,此方法无效。
Type Script + ionic 2如何工作?
您可以为此使用平台信息。
在内部,platform
使用window.innerWidth
和window.innerHeight
,但
首选使用此方法,因为维度是缓存的值,这减少了多次读取和昂贵的DOM读取的机会。
文件:https : //ionicframework.com/docs/angular/platform#width-number
import { Component } from '@angular/core';
import { Platform } from '@ionic/angular';
@Component({...})
export MyApp {
constructor(platform: Platform) {
platform.ready().then(() => {
console.log('Width: ' + platform.width());
console.log('Height: ' + platform.height());
});
}
}
文件:https : //ionicframework.com/docs/v3/api/platform/Platform/#width
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
@Component({...})
export MyApp {
constructor(platform: Platform) {
platform.ready().then(() => {
console.log('Width: ' + platform.width());
console.log('Height: ' + platform.height());
});
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句