UserAgent detector using Platform.js for Nuxt.
npm install --save nuxt-ua
This module is compatible with Nuxt 2, Nuxt 3 and Nuxt-bridge.
Add 'nuxt-ua'
to your modules
array in the nuxt.config.ts
file:
modules: [
// other modules...
'nuxt-ua',
]
If you are using TypeScript in a Nuxt2 project, please add nuxt-ua/types
to your tsconfig.json
file to inject $ua
into the Context
:
{
"compilerOptions": {
// ..
"types": [
"@nuxt/types",
"@types/node",
"nuxt-ua/types"
]
}
}
Then, you can use the $ua
object:
<template>
<main>
{{ $ua.is.chrome ? 'This is Chrome' : 'This is not Chrome' }}
</main>
</template>
<script lang="ts">
import Vue from 'vue';
import { Context } from '@nuxt/vue-app/types';
export default Vue.extend({
fetch(context: Context) {
console.log(context.$ua);
}
});
</script>
Returns a Platform
object.
Returns true
if the UserAgent is Chrome.
Returns true
if the UserAgent is Firefox.
Returns true
if the UserAgent is Safari.
Returns true
if the UserAgent is Internet Explorer.
Returns true
if the UserAgent is Microsoft Edge.
Returns true
if the UserAgent is Opera.
Returns true
if the UserAgent is Android.
Returns true
if the UserAgent is iOS.
Returns true
if the UserAgent is macOS.
Returns true
if the UserAgent is Windows.
Returns true
if the UserAgent is Linux.
- Install the development dependencies
npm ci
- Initialize the Nuxt playground
npm run dev:prepare
- Run the development environment
npm run dev
- Add or modify the tests and ensure that tests are passing
npm test