平台检测
isPlatform
isPlatform 方法可用于检测您的应用是否运行在特定平台上:
import { isPlatform } from '@ionic/vue';
isPlatform('ios'); // 在 iOS 设备上运行时返回 true
根据用户所在的平台,isPlatform(platformName) 会返回 true 或 false。请注意,同一个应用可能对多个平台名称返回 true。例如,在 iPad 上运行的应用会对以下平台名称返回 true:mobile、ios、ipad 和 tablet。此外,如果应用运行在 Cordova 环境中,则 cordova 也会返回 true。
getPlatforms
getPlatforms 方法可用于确定您的应用当前运行在哪些平台上。
import { getPlatforms } from '@ionic/vue';
getPlatforms(); // 在 iPhone 上返回 ["iphone", "ios", "mobile", "mobileweb"]
根据您使用的设备,getPlatforms 可能返回多个值。每个可能的值代表一个平台层级。例如,在 iPhone 上,它会返回 mobile、ios 和 iphone。