mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
docs(plugins): usage with vue plugins (#1129)
Co-authored-by: pooya parsa <pyapar@gmail.com>
This commit is contained in:
parent
7c3b488b5f
commit
d365a45eb1
@ -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
|
||||||
|
@ -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,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user