chore: StackGuard
All checks were successful
CI / cache-and-install (push) Successful in 55s

This commit is contained in:
严浩
2024-08-10 16:41:48 +08:00
parent 0afdfc5d2c
commit d0ba655182
16 changed files with 251 additions and 181 deletions

View File

@ -1,13 +1,73 @@
<script setup lang="ts">
<script lang="ts" setup>
import { router } from '@/router';
definePage({
alias: '/'
})
});
const testButtons = [
{
text: 'Page1 -> Page2',
onClick: async () => {
console.clear();
console.debug('⚙️ 预期结果:', ['Page1', 'Page2']);
await router.push({ name: 'Page1' });
await router.push({ name: 'Page2' });
}
},
{
text: 'A -> (B) -> C',
onClick: async () => {
console.clear();
console.debug('⚙️ 预期结果: ', ['Page1', 'Page3']);
await router.push({ name: 'Page1' });
await router.push({ name: 'Page2' });
await router.push({ name: 'Page3', replace: true });
}
},
{
text: 'A -> B -> C -> go(-2)',
onClick: async () => {
console.clear();
console.debug('⚙️ 预期结果: ', ['/', '/Page1📍', '/Page2', '/Page3']);
await router.push({ name: 'Page1' });
await router.push({ name: 'Page2' });
await router.push({ name: 'Page3' });
router.go(-2);
}
},
{
text: 'A -> B -> C -> go(-1) -> (D)',
onClick: async () => {
console.clear();
console.debug('⚙️ 预期结果: ', ['/', 'Page1', 'Page4📍', 'Page3']);
await router.push({ name: 'Page1' });
await router.push({ name: 'Page2' });
await router.push({ name: 'Page3' });
router.go(-1);
function popStateListener() {
console.debug('back执行完成, 替换"Page2"为"Page4"');
router.replace({ name: 'Page4' });
window.removeEventListener('popstate', popStateListener);
}
window.addEventListener('popstate', popStateListener);
}
}
];
</script>
<template>
<div class="flex gap-2">
<t-button @click="$router.push({ name: 'Page1' })">ToPage1</t-button>
<t-button @click="$router.push({ name: 'Page2' })">ToPage2</t-button>
<t-button @click="$router.push({ name: 'Page3' })">ToPage3</t-button>
<div class="flex flex-col gap-2 items-start">
<div class="flex gap-2">
<t-button @click="$router.push({ name: 'Page1' })">ToPage1</t-button>
<t-button @click="$router.push({ name: 'Page2' })">ToPage2</t-button>
<t-button @click="$router.push({ name: 'Page3' })">ToPage3</t-button>
</div>
<template v-for="btn in testButtons" :key="btn.text">
<t-button theme="primary" @click="btn.onClick">{{ btn.text }}</t-button>
</template>
</div>
</template>

View File

@ -27,5 +27,5 @@ function backToHome() {
onMounted(() => {
// console.log('router.currentRoute.value.from :>> ', router.currentRoute.value.from);
// backToHome()
})
});
</script>

1
src/pages/page-4.vue Normal file
View File

@ -0,0 +1 @@
<template>page-4</template>