Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/fukuiretu/nuxt-user-agent

Nuxt.js module for handling User-Agent.
https://github.com/fukuiretu/nuxt-user-agent

js nuxt nuxt-module nuxtjs

Last synced: about 1 month ago
JSON representation

Nuxt.js module for handling User-Agent.

Awesome Lists containing this project

README

        

# nuxt-user-agent



MIT License


npm version












[Nuxt.js](https://nuxtjs.org/) module for handling User-Agent.

Inspired by [rack-user-agent](https://github.com/k0kubun/rack-user_agent) and, Thanks to [woothee](http://woothee.github.io/) :pray:

## Setup

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',
]
}
```

## Usage

### Component

##### 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

```

## 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.](https://opensource.org/licenses/MIT)