|
| 1 | +## vue3-device-detect |
| 2 | + |
| 3 | +[](https://www.npmjs.com/package/@basitcodeenv/vue3-device-detect) |
| 4 | +[](https://github.com/basitcodeenv/vue3-device-detect/blob/main/LICENSE) |
| 5 | +[](https://github.com/vuejs/vue) |
| 6 | +[](https://github.com/basitcodeenv/vue3-device-detect) |
| 7 | +[](https://npmcharts.com/compare/@basitcodeenv/vue3-device-detect?minimal=true) |
| 8 | + |
| 9 | +Detect device type and render content based on device type |
| 10 | + |
| 11 | +## Quickstart |
| 12 | + |
| 13 | +Install using |
| 14 | + |
| 15 | +``` |
| 16 | +npm install @basitcodeenv/vue3-device-detect --save |
| 17 | +``` |
| 18 | + |
| 19 | +Then, initalize the plugin in the starting point of your app (most likely src/main.js): |
| 20 | + |
| 21 | +```ts |
| 22 | +// main.ts |
| 23 | +import VueDeviceDetect from '@basitcodeenv/vue3-device-detect' |
| 24 | +Vue.use(vueDeviceDetect) |
| 25 | +``` |
| 26 | + |
| 27 | +This will globally register the components `DesktopView`, `MobileView` and others and you will be able to use those right away. |
| 28 | + |
| 29 | +<!-- prettier-ignore --> |
| 30 | +```html |
| 31 | +<template> |
| 32 | + <DesktopView> |
| 33 | + <h1>This is rendered only in desktop browser</h1> |
| 34 | + </DesktopView> |
| 35 | + |
| 36 | + <MobileView> |
| 37 | + <h1>This is rendered only on mobile</h1> |
| 38 | + </MobileView> |
| 39 | +</template> |
| 40 | +``` |
| 41 | + |
| 42 | +Build-in components: |
| 43 | + |
| 44 | + AndroidView |
| 45 | + ChromeView |
| 46 | + ChromiumView |
| 47 | + ConsoleView |
| 48 | + DesktopView |
| 49 | + EdgeChromiumView |
| 50 | + EdgeLegacyView |
| 51 | + EdgeView |
| 52 | + ElectronView |
| 53 | + EmbeddedView |
| 54 | + FirefoxView |
| 55 | + IEView |
| 56 | + IOSView |
| 57 | + IPadView |
| 58 | + IPhoneView |
| 59 | + IPodView |
| 60 | + LinuxView |
| 61 | + MacOSView |
| 62 | + MIUIView |
| 63 | + MobileOnlyView |
| 64 | + MobileSafariView |
| 65 | + MobileView |
| 66 | + OperaView |
| 67 | + SafariView |
| 68 | + SamsungBrowserView |
| 69 | + SmartTVView |
| 70 | + TabletView |
| 71 | + WearableView |
| 72 | + WindowsView |
| 73 | + WinPhoneView |
| 74 | + YandexView |
| 75 | + |
| 76 | +You can also determine through the built-in API |
| 77 | + |
| 78 | +```ts |
| 79 | +// main.ts |
| 80 | +import { isMobile } from '@basitcodeenv/vue3-device-detect' |
| 81 | +``` |
| 82 | + |
| 83 | +## API |
| 84 | + |
| 85 | +Properties: |
| 86 | + |
| 87 | +| name | type | description | |
| 88 | +| ---------------- | ------- | --------------------------------------- | |
| 89 | +| isAndroid | boolean | The OS is `Android` | |
| 90 | +| isChrome | boolean | Browser is `Chrome` | |
| 91 | +| isChromium | boolean | Browser is `Chromium` | |
| 92 | +| isConsole | boolean | The device type is `console` | |
| 93 | +| isDesktop | boolean | The device type is `desktop` | |
| 94 | +| isEdge | boolean | Browser is `Edge` or `Edge Chromium` | |
| 95 | +| isEdgeChromium | boolean | Browser is `Edge Chromium` | |
| 96 | +| isEdgeLegacy | boolean | Browser is `Edge` | |
| 97 | +| isElectron | boolean | Browser is `Electron` | |
| 98 | +| isEmbedded | boolean | The device type is `embedded` | |
| 99 | +| isFirefox | boolean | Browser is `Firefox` | |
| 100 | +| isIE | boolean | Browser is `Internet Explorer` | |
| 101 | +| isIOS | boolean | The OS is `iOS` | |
| 102 | +| isIPad | boolean | is `iPad` | |
| 103 | +| isIPhone | boolean | is `iPhone` | |
| 104 | +| isIPod | boolean | is `iPod` | |
| 105 | +| isLinux | boolean | The OS is `Linux` | |
| 106 | +| isMacOS | boolean | The OS is `Mac OS` | |
| 107 | +| isMIUI | boolean | Browser is `MIUI Browser` | |
| 108 | +| isMobile | boolean | The device type is `mobile` or `tablet` | |
| 109 | +| isMobileOnly | boolean | The device type is `mobile` | |
| 110 | +| isMobileSafari | boolean | Browser is `Mobile Safari` | |
| 111 | +| isOpera | boolean | Browser is `Opera` | |
| 112 | +| isSafari | boolean | Browser is `Safari` | |
| 113 | +| isSamsungBrowser | boolean | Browser is `Samsung Browser` | |
| 114 | +| isSmartTV | boolean | The device type is `smarttv` | |
| 115 | +| isTablet | boolean | The device type is `tablet` | |
| 116 | +| isWearable | boolean | The device type is `wearable` | |
| 117 | +| isWindows | boolean | The OS is `Windows` | |
| 118 | +| isWinPhone | boolean | The OS is `Windows Phone` | |
| 119 | +| isYandex | boolean | Browser is `Yandex Browser` | |
| 120 | + |
| 121 | +Functions: |
| 122 | + |
| 123 | +| name | return type | description | |
| 124 | +| -------------- | ----------- | ------------------------------------------------------------------------ | |
| 125 | +| browserName | string | Return browser name | |
| 126 | +| browserVersion | string | Return browser version | |
| 127 | +| deviceModel | string | Return mobile device type (e.g `Nexus 5`) | |
| 128 | +| deviceType | string | Return device type (`mobile` or `tablet`) | |
| 129 | +| deviceVendor | string | Return mobile phone brand (e.g `LG`, `Apple iPhone` etc) | |
| 130 | +| engineName | string | Return browser engine name (e.g `Gecko` for Firefox, `Blink` for Chrome) | |
| 131 | +| engineVersion | string | Return browser engine version | |
| 132 | +| getUA | string | Return user agent | |
| 133 | +| osName | string | Return OS name | |
| 134 | +| osVersion | string | Return OS version | |
0 commit comments