Nuxt.js module for handling User-Agent.
npm install nuxt-user-agentNuxt.js module for handling User-Agent.
Inspired by rack-user-agent and, Thanks to woothee :pray:
Install with yarn:
yarn add nuxt-user-agent
Install with npm:
npm install nuxt-user-agent
nuxt.config.js
``js`
module.exports = {
modules: [
'nuxt-user-agent',
]
}
##### asyncData
`js`
asyncData(context) {
const deviceType = context.$ua.deviceType()
return { deviceType }
}
##### methods/created/mounted/etc
`js`
methods: {
something() {
const deviceType = this.$ua.deviceType()
this.deviceType = deviceType
}
}
##### Store actions
`js`
// In store
{
actions: {
getDeviceType ({ commit }) {
const deviceType = this.$ua.deviceType()
commit('SET_DEVICE_TYPE', deviceType)
}
}
}
##### template
`vue``
PC
Smartphone
Mobilephone
Tablet
Appliance
Crawler
| 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 |