🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

nuxt-device-is

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
n

nuxt-device-is

Library to detect mobile/tablet/desktop devices on server and in browser.

1.2.3
latest
71

Supply Chain Security

100

Vulnerability

100

Quality

76

Maintenance

100

License

AI-detected possible typosquat

Supply chain risk

There is a package with a similar name that is downloaded much more often.

Did you mean

@nuxtjs/device

Unpopular package

Quality

This package is not very popular.

Found 1 instance in 1 package

Version published
Weekly downloads
90
-25.62%
Maintainers
1
Weekly downloads
 
Created
Issues
15

Nuxt-device-is

Library to detect mobile/tablet/desktop devices on server and in browser.

Installation

npm i nuxt-device-is

Usage

  • Add to nuxt.config.js module section
module.exports = {
    modules: [
        'nuxt-device-is',
    ],
};
  • Set yours breakpoints options for browser detection
module.exports = {
    NuxtDeviceIs: {
        breakpoints: {
            mobile: 720,
            tablet: 1024,
            laptop: 1440,
            desktop: 999999
        }
    },
};

That are default breakpoints.

  • Use $deviceIs instance wherever you want:

In Template section


<template>
    <button v-if="$deviceIs.mobile">mobile button</button>
    <button v-else-if="$deviceIs.desktop">desktop button</button>
</template>

In JavaScript section

export default {
    data() {
        return {
            children: [
                { ... },
                { ... },
                { ... },
                { ... },
                { ... },
                { ... },
                { ... },
                { ... },
            ]
        };
    },

    computed: {
        childrenList() {
            switch (this.$deviceIs.device) {
                case 'mobile':
                    return [...this.children].slice(0, 4);
                case 'tablet':
                    return [...this.children].slice(0, 6);
                default:
                    return this.children;
            }
        },
    },
}

Available computed options

this.$deviceIs.mobile;
this.$deviceIs.tablet;
this.$deviceIs.laptop;
this.$deviceIs.desktop;
this.$deviceIs.сrawler; // if device is search bot
this.$deviceIs.pc; // if device is laptop or desktop

Available device option values

['mobile', 'tablet', 'laptop', 'desktop']

FAQs

Package last updated on 20 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts