1.0.0 • Published 7 months ago

@tenrok/vue-device-detect v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

vue-device-detect

Detect device type and render content based on device type

Quickstart

Install using

npm install @tenrok/vue-device-detect --save

Then, initalize the plugin in the starting point of your app (most likely src/main.js):

// main.ts
import VueDeviceDetect from '@tenrok/vue-device-detect'
Vue.use(vueDeviceDetect)

This will globally register the components DesktopView, MobileView and others and you will be able to use those right away.

<template>
	<DesktopView>
		<h1>This is rendered only in desktop browser</h1>
	</DesktopView>

	<MobileView>
		<h1>This is rendered only on mobile</h1>
	</MobileView>
</template>

Build-in components:

AndroidView
ChromeView
ChromiumView
ConsoleView
DesktopView
EdgeChromiumView
EdgeLegacyView
EdgeView
ElectronView
EmbeddedView
FirefoxView
IEView
IOSView
IPadView
IPhoneView
IPodView
LinuxView
MacOSView
MIUIView
MobileOnlyView
MobileSafariView
MobileView
OperaView
SafariView
SamsungBrowserView
SmartTVView
TabletView
WearableView
WindowsView
WinPhoneView
YandexView

You can also determine through the built-in API

// main.ts
import { isMobile } from '@tenrok/vue-device-detect'

API

proptypedescription
isAndroidbooleanThe OS is Android
isChromebooleanBrowser is Chrome
isChromiumbooleanBrowser is Chromium
isConsolebooleanThe device type is console
isDesktopbooleanThe device type is desktop
isEdgebooleanBrowser is Edge or Edge Chromium
isEdgeChromiumbooleanBrowser is Edge Chromium
isEdgeLegacybooleanBrowser is Edge
isElectronbooleanBrowser is Electron
isEmbeddedbooleanThe device type is embedded
isFirefoxbooleanBrowser is Firefox
isIEbooleanBrowser is Internet Explorer
isIOSbooleanThe OS is iOS
isIPadbooleanis iPad
isIPhonebooleanis iPhone
isIPodbooleanis iPod
isLinuxbooleanThe OS is Linux
isMacOSbooleanThe OS is Mac OS
isMIUIbooleanBrowser is MIUI Browser
isMobilebooleanThe device type is mobile or tablet
isMobileOnlybooleanThe device type is mobile
isMobileSafaribooleanBrowser is Mobile Safari
isOperabooleanBrowser is Opera
isSafaribooleanBrowser is Safari
isSamsungBrowserbooleanBrowser is Samsung Browser
isSmartTVbooleanThe device type is smarttv
isTabletbooleanThe device type is tablet
isWearablebooleanThe device type is wearable
isWindowsbooleanThe OS is Windows
isWinPhonebooleanThe OS is Windows Phone
isYandexbooleanBrowser is Yandex Browser
functionreturn typedescription
browserNamestringReturn browser name
browserVersionstringReturn browser version
deviceModelstringReturn mobile device type (e.g Nexus 5)
deviceTypestringReturn device type (mobile or tablet)
deviceVendorstringReturn mobile phone brand (e.g LG, Apple iPhone etc)
engineNamestringReturn browser engine name (e.g Gecko for Firefox, Blink for Chrome)
engineVersionstringReturn browser engine version
getUAstringReturn user agent
osNamestringReturn OS name
osVersionstringReturn OS version