0.2.0 • Published 6 years ago

nuxt-detect-ua v0.2.0

Weekly downloads
13
License
MIT
Repository
github
Last release
6 years ago

nuxt-detect-ua

Nuxt.js module for handling User-Agent.

Forked from nuxt-user-agent.

Setup

yarn add nuxt-detect-ua
module.exports = {
  modules: [
    'nuxt-detect-ua',
  ]
}

Usage

Component

asyncData
asyncData(context) {
  const deviceType = context.$ua.deviceType()
  return { deviceType }
}
methods/created/mounted/etc
methods: {
  something() {
    const deviceType = this.$ua.deviceType()
    this.deviceType = deviceType
  }
}
Store actions
// In store
{
  actions: {
    getDeviceType ({ commit }) {
      const deviceType = this.$ua.deviceType()
      commit('SET_DEVICE_TYPE', deviceType)
    }
  }
}
template
<template>
  <section>
    <div v-if="$ua.isFromPc()">
      <span>PC</span>
    </div>
    <div v-if="$ua.isFromSmartphone()">
      <span>Smartphone</span>
    </div>
    <div v-if="$ua.isFromMobilephone()">
      <span>Mobilephone</span>
    </div>
    <div v-if="$ua.isFromTablet()">
      <span>Tablet</span>
    </div>
    <div v-if="$ua.isFromAppliance()">
      <span>Appliance</span>
    </div>
    <div v-if="$ua.isFromCrawler()">
      <span>Crawler</span>
    </div>
  </section>
</template>

Methods

methodtypeexample
deviceTypestringpc
osstringMac OSX
osVersionstring10.12.6
browserstringChrome
browserVersionstring65.0.3325.181
browserVendorstringGoogle
isFromIphonebooleantrue
isFromIpadbooleantrue
isFromIpodbooleantrue
isFromIosbooleantrue
isFromAndroidbooleantrue
isFromAndroidTabletbooleantrue
isFromWindowsPhonebooleantrue
isFromPcbooleantrue
isFromSmartphonebooleantrue
isFromMobilephonebooleantrue
isFromAppliancebooleantrue
isFromCrawlerbooleantrue
isFromTabletbooleantrue

License

The npm is available as open source under the terms of the MIT License.