MatteoGabriele / vue-gtag

Global Site Tag plugin for Vue (gtag.js)
https://matteo-gabriele.gitbook.io/vue-gtag/
MIT License
870 stars 67 forks source link

VueJS 3 + TypeScript compatibility #314

Closed davellanedam closed 3 years ago

davellanedam commented 3 years ago

Description

Errors when trying to use vue-gtag with Vue 3 + TS

image

Environment

vue-gtag@2.0.0

Reproducible Demo

main.ts

import { createApp } from 'vue';
import App from './App.vue';

import './assets/styles/main.css';

const app = createApp(App, { getApp: () => app });
app.mount('#app');

App.vue

<template>
  <div>
    <router-view />
  </div>
</template>

<script lang="ts">
import { App, defineComponent, PropType } from 'vue';
import { loadGoogleTags } from './services/googleTags';

export default defineComponent({
  name: 'App',
  props: {
    getApp: { required: true, type: Function as PropType<() => App> }
  },
  setup(props) {
    const app = props.getApp();
    // Load other services...
    loadGoogleTags(app);
  }
});
</script>

googleTags.ts

import { App } from 'vue';
import VueGtag from 'vue-gtag';

export function loadGoogleTags(app: App) {
  app.use(VueGtag, {
    config: { id: process.env.VUE_APP_GOOGLE_TAGS_CODE }
  });
}
MatteoGabriele commented 3 years ago

:tada: This issue has been resolved in version 2.0.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: