This vue plugin allows you to (dynamically) set up your Cookiebot implementation and load the consent banner and consent page on demand
- Install module:
npm i @nafia123/vue-3-cookiebot-plugin --save
oryarn add @nafia123/vue-3-cookiebot-plugin
- Go to the main JS-file of your Vue app and add the following:
import Vue from 'vue'
...
import VueCookieBot from '@nafia123/vue-3-cookiebot-plugin'
Vue.use(VueCookieBot, {
cookieBotID: 'insert your cookiebot ID here'
})
const app = new Vue({
...
})
The variable $cookiebot
has been added to the Vue instance. You can trigger the consent banner where you'd like by executing:
<script>
export default {
name: 'MyVueComponent',
mounted () {
this.$cookiebot.consentBanner()
}
}
</script>
The variable $cookiebot
can now be injected. You can trigger the consent banner where you'd like after defining a $cookiebot
variable:
See Provide/ Inject for more information about Provide/ Inject API
<script>
setup() {
const $cookiebot = inject('$cookiebot');
}
export default {
name: 'MyVueComponent',
mounted () {
$cookiebot.consentBanner()
}
}
</script>
For the full API reference regarding the Vue Plugin install method, see the Vue plugin install docs
For a list of available methods and properties on the $cookiebot
instance, see the Vue plugin methods docs