# nuxt-device-detect

> This module injects flags that indicate a device type into the context and the component instance.

Latest version **1.1.5** (published 2019-05-20) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install nuxt-device-detect
pnpm add nuxt-device-detect
yarn add nuxt-device-detect
bun add nuxt-device-detect
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.1.5 |
| Published | 2019-05-20 |
| First published | 2017-12-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1006 |
| Author | shinji yamada |
| Maintainers | devneko |

## Links

- npm: https://www.npmjs.com/package/nuxt-device-detect
- Repository: https://github.com/dotneet/nuxt-device-detect
- Homepage: https://github.com/dotneet/nuxt-device-detect#readme
- Issues: https://github.com/dotneet/nuxt-device-detect/issues
- npm.io page: https://npm.io/package/nuxt-device-detect

## Recent versions

- 1.1.5 (latest) — 2019-05-20
- 1.1.4 — 2019-03-11
- 1.1.3 — 2019-01-22
- 1.1.2 — 2018-10-24
- 1.1.1 — 2018-03-09
- 1.1.0 — 2018-01-23
- 1.0.0 — 2017-12-08

## README

# nuxt-device-detect

This module injects flags that indicate a device type into the context and the component instance.

[![nuxt-device-detect Dev Token](https://badge.devtoken.rocks/nuxt-device-detect)](https://devtoken.rocks/package/nuxt-device-detect)

## Setup

 - Add `nuxt-device-detect` to depedency using yarn or npm to your project
 - Add `nuxt-device-detect` to modules section of nuxt.config.js

```js
{
  modules: [
   'nuxt-device-detect',
  ]
}
```

### Options

`defaultUserAgent` option can be used for `npm run generate`.

```js
{
  modules: [
    [
      'nuxt-device-detect',
      {defaultUserAgent: 'Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.39 Mobile Safari/537.36'}
    ]
  ]
}
```

## Added flags

you can use these flags to detect the device type.

```js
context.isDesktop
context.isMobile
context.isTablet
context.isMobileOrTablet
context.isDesktopOrTablet
context.isIos
context.isWindows
context.isMacOS

instance.$device.isDesktop
instance.$device.isMobile
instance.$device.isTablet
instance.$device.isMobileOrTablet
instance.$device.isDesktopOrTablet
instance.$device.isIos
instance.$device.isWindows
instance.$device.isMacOS
```

## CloudFront Support

If a user-agent is 'Amazon CloudFront', nuxt-device-detect checks
the both headers 'CloudFront-Is-Mobile-Viewer' and 'CloudFront-Is-Tablet-Viewer'.

Here are the details about the headers:
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/header-caching.html#header-caching-web-device

### Caution

`isIos`, `isWindows` and `isMacOS` flags are not available with CloudFront.

## Usage

### Switch a view

```html
<template>
	<section>
		<div v-if="$device.isDesktop">
			Desktop
		</div>
		<div v-else-if="$device.isTablet">
			Tablet
		</div>
		<div v-else>
			Mobile
		</div>
	</section>
</template>
```

Ofcourse, you can use `$device` via `this` in a script.

### Change a layout dynamically

```js
export default {
	layout: (ctx) => ctx.isMobile ? 'mobile' : 'default'
}
```

---
_Source: https://npm.io/package/nuxt-device-detect · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
