GithubHelp home page GithubHelp logo

iliyazelenko / device-module Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nuxt-modules/device

0.0 1.0 0.0 85 KB

Nuxt.js module for detecting device type.

License: MIT License

JavaScript 100.00%

device-module's Introduction

@nuxtjs/device

npm version npm downloads Dependencies License Standard JS nuxt-device-detect Dev Token

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

Setup

  • Add @nuxtjs/device to depedency using yarn or npm to your project
  • Add @nuxtjs/device to modules section of nuxt.config.js
{
  modules: [
   '@nuxtjs/device',
  ]
}

Options

defaultUserAgent option can be used for npm run generate.

{
  modules: [
    [
      '@nuxtjs/device',
      {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.

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', this module 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

Cloudflare Support

This module checks the header 'CF-Device-Type'.

Here are the details about the header: https://support.cloudflare.com/hc/en-us/articles/229373388-Cache-Content-by-Device-Type-Mobile-Tablet-Desktop-

Caution

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

Usage

Switch a view

<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

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

License

MIT License

device-module's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.