提交代码
This commit is contained in:
49
src/home.vue
49
src/home.vue
@ -1,14 +1,57 @@
|
||||
<script setup>
|
||||
import Header from './views/layout/pc/header/index.vue'
|
||||
import Footer from './views/layout/pc/footer/index.vue'
|
||||
import {onMounted, ref, watch} from 'vue'
|
||||
import {visit} from '@/api/index'
|
||||
import axios from 'axios'
|
||||
|
||||
onMounted(() => {
|
||||
getUrl()
|
||||
})
|
||||
|
||||
const referrer = ref('')
|
||||
const ipUrl = ref('')
|
||||
|
||||
console.log('11===>', window.location)
|
||||
function getUrl() {
|
||||
referrer.value = document.referrer
|
||||
|
||||
axios
|
||||
.get('https://api64.ipify.org?format=json')
|
||||
.then(({data}) => {
|
||||
ipUrl.value = data.ip
|
||||
})
|
||||
.catch(console.error)
|
||||
}
|
||||
|
||||
async function postVisit() {
|
||||
let params = {
|
||||
timestamp: new Date(),
|
||||
url: window.location.href,
|
||||
referrer: referrer.value,
|
||||
real_ip: ipUrl.value,
|
||||
}
|
||||
let {code, msg} = await visit(params)
|
||||
}
|
||||
|
||||
watch(
|
||||
() => [referrer.value, ipUrl.value],
|
||||
([refer, ipUrl]) => {
|
||||
if (refer && ipUrl) {
|
||||
postVisit()
|
||||
}
|
||||
},
|
||||
{
|
||||
deep: true,
|
||||
immediate: true,
|
||||
}
|
||||
)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div id="app">
|
||||
<Header id="header" />
|
||||
|
||||
<!-- include 对应组件的 name -->
|
||||
<router-view id="main" v-slot="{Component}">
|
||||
<router-view id="main" v-slot="{Component, title}">
|
||||
<keep-alive include="New">
|
||||
<component :is="Component" />
|
||||
</keep-alive>
|
||||
|
||||
Reference in New Issue
Block a user