Commit 72af6f7c53a79e8117a45f68e7fb01665ae34f86
1 parent
69a96497
购好物,添加测试页面,获取浏览器唯一标识~
Showing
2 changed files
with
73 additions
and
1 deletions
src/pages/getBrowersAgent/getBrowersAgent.vue
0 → 100644
| 1 | +<template> | |
| 2 | + <div> | |
| 3 | + 获取浏览器唯一标识 | |
| 4 | + </div> | |
| 5 | +</template> | |
| 6 | + | |
| 7 | +<script> | |
| 8 | + | |
| 9 | + export default { | |
| 10 | + name: 'getBrowersAgentPage', | |
| 11 | + data () { | |
| 12 | + return { | |
| 13 | + | |
| 14 | + } | |
| 15 | + }, | |
| 16 | + components: { | |
| 17 | + | |
| 18 | + }, | |
| 19 | + computed: { | |
| 20 | + | |
| 21 | + }, | |
| 22 | + created() { | |
| 23 | + | |
| 24 | + }, | |
| 25 | + methods: { | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * 获取浏览器唯一标识 | |
| 29 | + */ | |
| 30 | + getBrowersAgent() { | |
| 31 | + | |
| 32 | + // 初始化Promise对象 | |
| 33 | + const fpPromise = new Promise((resolve, reject) => { | |
| 34 | + const script = document.createElement('script'); | |
| 35 | + script.onload = resolve; | |
| 36 | + script.onerror = reject; | |
| 37 | + script.async = true; | |
| 38 | + script.src = 'https://cdn.jsdelivr.net/npm/@fingerprintjs/fingerprintjs@3/dist/fp.min.js'; | |
| 39 | + document.head.appendChild(script); | |
| 40 | + }).then(() => FingerprintJS.load()); | |
| 41 | + | |
| 42 | + // Get the visitor identifier when you need it. | |
| 43 | + fpPromise.then(fp => fp.get()).then(result => { | |
| 44 | + | |
| 45 | + // This is the visitor identifier | |
| 46 | + const visitorId = result.visitorId; | |
| 47 | + | |
| 48 | + // 测试代码,控制台输出浏览器唯一标识 | |
| 49 | + console.log(visitorId); | |
| 50 | + }); | |
| 51 | + } | |
| 52 | + }, | |
| 53 | + mounted() { | |
| 54 | + | |
| 55 | + // 获取浏览器唯一标识 | |
| 56 | + this.getBrowersAgent(); | |
| 57 | + } | |
| 58 | + } | |
| 59 | +</script> | |
| 0 | 60 | \ No newline at end of file | ... | ... |
src/router/index.js
| ... | ... | @@ -364,8 +364,21 @@ const router = new Router({ |
| 364 | 364 | meta: { |
| 365 | 365 | requireAuth: false |
| 366 | 366 | } |
| 367 | - } | |
| 367 | + }, | |
| 368 | 368 | /* 健步走健康值商城结束 */ |
| 369 | + { | |
| 370 | + // 获取浏览器唯一标识(测试页面) | |
| 371 | + path: "/getBrowersAgent", | |
| 372 | + name: "getBrowersAgent", | |
| 373 | + component: resolve => { | |
| 374 | + require([ | |
| 375 | + "@/pages/getBrowersAgent/getBrowersAgent" | |
| 376 | + ], resolve); | |
| 377 | + }, | |
| 378 | + meta: { | |
| 379 | + requireAuth: false | |
| 380 | + } | |
| 381 | + } | |
| 369 | 382 | ] |
| 370 | 383 | }, |
| 371 | 384 | { | ... | ... |