1 | ![Nuxt Cookie Control](https://drive.google.com/a/broj42.com/uc?id=12TegiHCNYG1NO84CmQ2CfMAzzn-5o027)
|
2 | # Nuxt Cookie Control
|
3 | Try it out here:
|
4 | [Nuxt.js Cookie Control](https://codesandbox.io/s/vkwqmm577)
|
5 | [![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FJPYXXXL4SQSE&source=url)
|
6 | ## Usage
|
7 | | npm install nuxt-cookie-control | yarn add nuxt-cookie-control |
|
8 | |--|--|
|
9 | ```javascript
|
10 | //nuxt.config.js
|
11 | modules: [
|
12 | 'nuxt-cookie-control'
|
13 | ]
|
14 | //or
|
15 | modules: [
|
16 | ['nuxt-cookie-control', {
|
17 | //your options
|
18 | }]
|
19 | ]
|
20 |
|
21 | //to open cookie modal anywhere:
|
22 | $cookies.modal = true
|
23 | //or
|
24 | this.$cookies.modal = true
|
25 | ```
|
26 | ```html
|
27 | <!--template-->
|
28 | <!--
|
29 | CookieControl component is registered globally,
|
30 | you don't need to register it anywhere.
|
31 | -->
|
32 | <CookieControl/>
|
33 | <!--or-->
|
34 | <CookieControl></CookieControl>
|
35 | ```
|
36 | ## Slot
|
37 | If you want to add elements to the cookie bar you can do it like this
|
38 | ```html
|
39 | <CookieControl>
|
40 | <template v-slot:bar>
|
41 | <h3>Bar title</h3>
|
42 | <p>Bar description (you can use $cookies.text.barDescription)</p>
|
43 | <n-link>Go somewhere</n-link>
|
44 | </template>
|
45 |
|
46 | <template v-slot:modal>
|
47 | <h3>Modal title</h3>
|
48 | <p>Modal description</p>
|
49 | </template>
|
50 | </CookieControl>
|
51 | ```
|
52 |
|
53 | ## Props
|
54 | ### Locale
|
55 | ```html
|
56 | <CookieControl locale="de"/>
|
57 | ```
|
58 | #### Default: en,
|
59 | #### Currently available:
|
60 | - en
|
61 | - de
|
62 | - it
|
63 | - es
|
64 | - fr
|
65 | - hr
|
66 |
|
67 | ## Options
|
68 | Options in nuxt.config.js
|
69 | ```javascript
|
70 | modules: [
|
71 | ['nuxt-cookie-control', {
|
72 | //default css (true)
|
73 | //if css is set to false, you will still be able to access
|
74 | //your color variables (example. background-color: var(--cookie-control-barBackground))
|
75 | css: true,
|
76 |
|
77 | //in case you have subdomains (shop.yourdomain.com)
|
78 | domain: 'yourdomain.com',
|
79 |
|
80 | //block iframes to prevent them from adding additional cookies
|
81 | blockIframe: true,
|
82 |
|
83 | //position of cookie bar:
|
84 | //'top-left', 'top-right', 'top-full',
|
85 | //'bottom-left', 'bottom-right', 'bottom-full'
|
86 | barPosition: 'bottom-full',
|
87 |
|
88 | //default colors
|
89 | colors: {
|
90 | barTextColor: '#fff',
|
91 | modalOverlay: '#000',
|
92 | barBackground: '#000',
|
93 | barButtonColor: '#000',
|
94 | modalTextColor: '#000',
|
95 | modalBackground: '#fff',
|
96 | modalOverlayOpacity: 0.8,
|
97 | modalButtonColor: '#fff',
|
98 | modalUnsavedColor: '#fff',
|
99 | barButtonHoverColor: '#fff',
|
100 | barButtonBackground: '#fff',
|
101 | modalButtonHoverColor: '#fff',
|
102 | modalButtonBackground: '#000',
|
103 | barButtonHoverBackground: '#333',
|
104 | checkboxActiveBackground: '#000',
|
105 | checkboxInactiveBackground: '#000',
|
106 | modalButtonHoverBackground: '#333',
|
107 | checkboxDisabledBackground: '#ddd',
|
108 | checkboxActiveCircleBackground: '#fff',
|
109 | checkboxInactiveCircleBackground: '#fff',
|
110 | checkboxDisabledCircleBackground: '#fff',
|
111 | },
|
112 |
|
113 | //default texts
|
114 | text: {
|
115 | barTitle: 'Cookies',
|
116 | barDescription: 'We use our own cookies and third-party cookies so that we can show you this website and better understand how you use it, with a view to improving the services we offer. If you continue browsing, we consider that you have accepted the cookies.',
|
117 | acceptAll: 'Accept all',
|
118 | declineAll: 'Delete all',
|
119 | manageCookies: 'Manage cookies',
|
120 | unsaved: 'You have unsaved settings',
|
121 | close: 'Close',
|
122 | save: 'Save',
|
123 | necessary: 'Necessary cookies',
|
124 | optional: 'Optional cookies',
|
125 | functional: 'Functional cookies',
|
126 | blockedIframe: 'To see this, please enable functional cookies',
|
127 | here: 'here'
|
128 | }
|
129 | ]
|
130 | ]
|
131 |
|
132 | //for multilanguage see - Multilanguage
|
133 | ```
|
134 | without options (Simple)
|
135 | ```javascript
|
136 | modules: [
|
137 | 'nuxt-cookie-control'
|
138 | ]
|
139 | ```
|
140 | ### Cookies
|
141 | ```javascript
|
142 | modules: [
|
143 | 'nuxt-cookie-control'
|
144 | ]
|
145 | ...
|
146 | ...
|
147 | ...
|
148 | cookies: {
|
149 | necessary: [
|
150 | {
|
151 | //if multilanguage
|
152 | name: {
|
153 | en: 'Default Cookies'
|
154 | }
|
155 | //else
|
156 | name: 'Default Cookies',
|
157 | //if multilanguage
|
158 | description: {
|
159 | en: 'Used for cookie control.'
|
160 | },
|
161 | //else
|
162 | description: 'Used for cookie control.',
|
163 | cookies: ['cookie_control_consent', 'cookie_control_enabled_cookies']
|
164 | }
|
165 | ],
|
166 | optional: [
|
167 | {
|
168 | name: 'Google Analitycs',
|
169 | //if multilanguage
|
170 | description: {
|
171 | en: 'Google GTM is ...'
|
172 | },
|
173 | //else
|
174 | description: 'Google GTM is...',
|
175 | src: 'https://www.googletagmanager.com/gtag/js?id=<API-KEY>',
|
176 | async: true,
|
177 | cookies: ['_ga', '_gat', '_gid'],
|
178 | accepted: () =>{
|
179 | window.dataLayer = window.dataLayer || [];
|
180 | window.dataLayer.push({
|
181 | 'gtm.start': new Date().getTime(),
|
182 | event: 'gtm.js'
|
183 | });
|
184 | },
|
185 | declined: () =>{
|
186 | }
|
187 | }
|
188 | ]
|
189 | }
|
190 | ```
|
191 | ### Multilanguage
|
192 | Set **locale** prop
|
193 | ```html
|
194 | <CookieControl locale="de"/>
|
195 | ```
|
196 | #### Default: en,
|
197 | #### Currently available:
|
198 | - en
|
199 | - de
|
200 | - it
|
201 | - es
|
202 | - fr
|
203 | - hr
|
204 |
|
205 | If you don't like the default texts you can change them in options (**nuxt.config.js**)
|
206 | ```javascript
|
207 | text: {
|
208 | locale: {
|
209 | en: {
|
210 | barTitle: 'Cookies Different',
|
211 | barDescription: 'We use our own cookies and third-party...',
|
212 | },
|
213 |
|
214 | de: {
|
215 | ...
|
216 | }
|
217 | }
|
218 |
|
219 | //this will override locale text
|
220 | barTitle: 'Override Title'
|
221 | }
|
222 | ``` |
\ | No newline at end of file |