1.0.1 • Published 3 months ago

@tenrok/vue3-device-detect v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

vue3-device-detect

Version License vue GitHub last commit Downloads

Detect device type and render content based on device type

This is Vue 3 compatible version. If you are using Vue 2 Click Here

Quickstart

Install using

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

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

// main.ts
import { DeviceDetectPlugin } from '@tenrok/vue3-device-detect'
app.use(DeviceDetectPlugin)

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/vue3-device-detect'

API

Properties:

nametypedescription
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

Functions:

namereturn 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
1.0.1

3 months ago

1.0.0

3 months ago