This commit is contained in:
2021-09-25 10:01:24 +08:00
parent a814040995
commit 943c07051c
7 changed files with 13 additions and 58 deletions

View File

@@ -4,34 +4,15 @@
<component :is="Component"></component>
</keep-alive>
</router-view>
<div>
<router-link :to="{name:'Home'}">Home</router-link>
|
<router-link :to="{name:'User'}">User</router-link>
|
<router-link :to="{name:'AuthLogin'}">Login</router-link>
|
<router-link :to="{name:'AuthRegister'}">Register</router-link>
</div>
</template>
<script lang="ts" setup>
import { INVITE_CODE } from '@/store'
import qs from 'qs'
import { ref, watch } from 'vue'
import { RouteLocationNormalizedLoaded, useRoute } from 'vue-router'
const includeList = ref<string[]>([])
const route = useRoute()
const { search } = location
if (search && search.indexOf('?') !== -1) {
const { invite } = qs.parse(location.search.slice(1))
invite && localStorage.setItem(INVITE_CODE, invite as string)
}
watch(route, (to: RouteLocationNormalizedLoaded) => {
if (to.meta?.keepAlive && includeList.value.indexOf(to.name as string) === -1) {
includeList.value.push(to.name as string)

View File

@@ -7,7 +7,6 @@ import auth, { AuthState } from './modules/auth'
import refresh, { RefreshState } from './modules/refresh'
export const PERSISTED_KEY = process.env.VUE_APP_VUEX_KEY
export const INVITE_CODE = 'invite_code'
export const key: InjectionKey<Store<State>> = Symbol()

View File

@@ -1,13 +1,11 @@
<template>
注册
<h2>邀请码 {{ invite }}</h2>
<button @click="onRegister">注册一个号</button>
</template>
<script lang="ts" setup>
import { INVITE_CODE, useStore } from '@/store'
import { useStore } from '@/store'
import type { AuthData } from '@/types/auth'
import { ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
@@ -15,7 +13,6 @@ import { useRoute, useRouter } from 'vue-router'
const store = useStore()
const route = useRoute()
const router = useRouter()
const invite = localStorage.getItem(INVITE_CODE)
const loading = ref<boolean>(false)
const onRegister = (e: AuthData) => {

View File

@@ -1,9 +1,6 @@
<template>
<div class="home">
<h1>{{ info.user_id }}</h1>
<h2>{{ info.nickname }}</h2>
<h3>{{ info.username }}</h3>
<img :src="info.avatar" width="80" alt="">
我是首页
</div>
</template>