nuxt-user-agent

Nuxt.js module for handling User-Agent.
272,403 121
Install
npm install nuxt-user-agent
Latest Version:1.2.2
Vue:2
License:MIT
Last Updated:Dec 3, 2022
Links: GitHub  ·  npm
Maintainer: fukuiretu

nuxt-user-agent

Nuxt.js module for handling User-Agent.

Inspired by rack-user-agent and, Thanks to woothee :pray:

Setup

Install with yarn:

yarn add nuxt-user-agent

Install with npm:

npm install nuxt-user-agent

nuxt.config.js

module.exports = {
  modules: [
    'nuxt-user-agent',
  ]
}

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

method type example
deviceType string pc
os string Mac OSX
osVersion string 10.12.6
browser string Chrome
browserVersion string 65.0.3325.181
browserVendor string Google
isFromIphone boolean true
isFromIpad boolean true
isFromIpod boolean true
isFromIos boolean true
isFromAndroidMobile boolean true
isFromAndroidTablet boolean true
isFromAndroidOs boolean true
isFromWindowsPhone boolean true
isFromPc boolean true
isFromSmartphone boolean true
isFromMobilephone boolean true
isFromAppliance boolean true
isFromCrawler boolean true
isFromTablet boolean true

TODO

  • unit test

License

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

Related Packages

nuxt-define

One utility function for module authors to define compiler constants for all bui...

13,412,511
@lg2/nuxt3-module-create-dato-map

nuxt3-module-create-dato-map

2,869 0
nuxt-csurf

Nuxt Cross-Site Request Forgery (CSRF) Prevention

6,263,746 91
@nuxtjs/dayjs

The best way for use Day.js easily in your Nuxt.js project.

404,248
@bg-dev/nuxt-naiveui

Unofficial Naive UI module for Nuxt

144,316 187

Version History

Version Released License
1.2.2 MIT
1.2.1 MIT
1.2.0 MIT
1.1.0 MIT
1.0.2 MIT