|
1 | 1 | <template> |
2 | | - <span class="site-count" ref="siteCountDom" v-show="isShow"> |
| 2 | + <span class="site-count" ref="siteCountDom" v-show="isShow && isProd"> |
3 | 3 | 超过 |
4 | 4 | <span id="busuanzi_value_site_uv" class="uv" v-show="isuv"></span> |
5 | 5 | <span id="busuanzi_value_site_pv" class="pv" v-show="!isuv"></span> |
6 | 6 | 次被使用 |
7 | 7 | </span> |
8 | 8 | </template> |
9 | 9 |
|
10 | | -<script lang="ts"> |
11 | | -import { defineComponent, onMounted, ref, Ref } from 'vue' |
| 10 | +<script setup lang="ts"> |
| 11 | +import { computed, onMounted, ref, Ref } from 'vue' |
12 | 12 |
|
13 | | -export default defineComponent({ |
14 | | - name: 'site-count', |
| 13 | +const props = defineProps({ |
| 14 | + isuv: { |
| 15 | + type: Boolean, |
| 16 | + default: false |
| 17 | + } |
| 18 | +}) |
15 | 19 |
|
16 | | - props: { |
17 | | - isuv: { |
18 | | - type: Boolean, |
19 | | - default: false |
20 | | - } |
21 | | - }, |
| 20 | +const siteCountDom: Ref = ref<null | HTMLElement>(null) |
| 21 | +const isShow: Ref<boolean> = ref(false) |
22 | 22 |
|
23 | | - setup(props, ctx) { |
24 | | - const siteCountDom: Ref = ref<null | HTMLElement>(null) |
25 | | - const isShow: Ref<boolean> = ref(false) |
| 23 | +const isProd = computed(() => import.meta.env.MODE === 'production') |
26 | 24 |
|
27 | | - const getInnerText = (dom, isuv) => { |
28 | | - return dom.querySelector(`.${isuv ? 'u' : 'p'}v`).innerText |
29 | | - } |
| 25 | +const getInnerText = (dom: any, isuv: boolean) => { |
| 26 | + return dom.querySelector(`.${isuv ? 'u' : 'p'}v`).innerText |
| 27 | +} |
30 | 28 |
|
31 | | - onMounted(() => { |
32 | | - const script: any = document.createElement('script') |
33 | | - script.async = true |
34 | | - script.src = '//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js' |
35 | | - siteCountDom.value.appendChild(script) |
| 29 | +onMounted(() => { |
| 30 | + const script: any = document.createElement('script') |
| 31 | + script.async = true |
| 32 | + script.src = '//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js' |
| 33 | + siteCountDom.value.appendChild(script) |
36 | 34 |
|
37 | | - script.onload = () => { |
38 | | - const tempT = setTimeout(() => { |
39 | | - if (getInnerText(siteCountDom.value, props.isuv)) { |
40 | | - isShow.value = true |
41 | | - } |
42 | | - clearTimeout(tempT) |
43 | | - }, 1500) |
| 35 | + script.onload = () => { |
| 36 | + const tempT = setTimeout(() => { |
| 37 | + if (getInnerText(siteCountDom.value, props.isuv)) { |
| 38 | + isShow.value = true |
44 | 39 | } |
45 | | - }) |
46 | | -
|
47 | | - return { |
48 | | - siteCountDom, |
49 | | - isShow |
50 | | - } |
| 40 | + clearTimeout(tempT) |
| 41 | + }, 1500) |
51 | 42 | } |
52 | 43 | }) |
53 | 44 | </script> |
|
0 commit comments