Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to check isAccepted() on mounted()? #73

Open
guiltyvictim opened this issue Oct 1, 2020 · 1 comment
Open

How to check isAccepted() on mounted()? #73

guiltyvictim opened this issue Oct 1, 2020 · 1 comment

Comments

@guiltyvictim
Copy link

vue & vue-cookie-law version

2.6.12, 1.13.3

Sorry I'm still really new to Vue.js and JS apps, but I'm not understanding how I'm supposed to check if cookie consent has been given when a visitor visits the page.

I wanted to use this to enable / disable vue-analytics. I assume I want to do a check on the isAccepted() method inside mounted(), but how? What is the function tied to? this.isAccepted() doesn't work, nor does CookieLaw.isAccepted()

I'm not using scoped version of the code, just literally just:

<cookie-law v-on:accept="enableTracking()" />

@alamo42
Copy link

alamo42 commented Dec 16, 2020

Hi, you need to create what on Vue.js is called a ref (Vue v3). Take this as a basic example:

<template>
  <vue-cookie-law ref="cookieBanner">
    Accept cookies, please!!
  </vue-cookie-law>
</template>

<script>
export default {
  computed: {
    areCookiesAccepted()  {
      return this.$refs.cookieBanner.isAccepted()
    }
  },
  mounted() {
    console.log(this.areCookiesAccepted) // true or false
  }
}
</script>

Hope it had helped :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants