docs(plugins): usage with vue plugins (#1129)

Co-authored-by: pooya parsa <pyapar@gmail.com>
This commit is contained in:
Bibek Shrestha 2021-10-20 09:33:33 -04:00 committed by GitHub
parent 7c3b488b5f
commit d365a45eb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View File

@ -39,7 +39,7 @@ In Nuxt 2 plugins, this was referred to as [inject function](https://nuxtjs.org/
```js ```js
const nuxtApp = { const nuxtApp = {
app, // the global Vue application: https://v3.vuejs.org/api/application-api.html vueApp, // the global Vue application: https://v3.vuejs.org/api/application-api.html
// These let you call and add runtime NuxtApp hooks // These let you call and add runtime NuxtApp hooks
// https://github.com/nuxt/framework/blob/main/packages/nuxt3/src/app/nuxt.ts#L18 // https://github.com/nuxt/framework/blob/main/packages/nuxt3/src/app/nuxt.ts#L18

View File

@ -41,3 +41,33 @@ declare module '#app' {
} }
} }
``` ```
## Vue plugins
If you want to use Vue plugins, like [vue-gtag](https://github.com/MatteoGabriele/vue-gtag) to add Google analytics tags, you can use a nuxt plugin to do so.
> There is an Open RFC to make this even easier! See [nuxt/framework#1175](https://github.com/nuxt/framework/discussions/1175)
First install the plugin you want.
```bash
yarn add --dev vue-gtag
```
Then create a plugin file `plugins/vue-gtag.client.js`.
```ts
import { defineNuxtPlugin } from "#app";
import VueGtag from "vue-gtag";
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.use(VueGtag, {
config: {
id: "GA_MEASUREMENT_ID",
params: {
anonymize_ip: true,
},
},
});
});
```