3 Star 4 Fork 6

Gitee 极速下载/vue-page-stack

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/hezhongfeng/vue-page-stack
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

vue-page-stack

Downloads Downloads
License Version

v3.2.0

  1. 修复 router.go 缓存失效的 bug

3.1.4

  1. 修复刷新浏览器然后后退的 bug

v3.1.3

  1. 修复 replace 时,页面缓存问题

v3.1.2

  1. 移除了 url 上的参数 stack-key
  2. 因为 Vue3.x 对内置组件有特殊处理,所以目前不能和 Transition 一起使用

这个是 Vue3.x 的版本 ,Vue2.0 请点击这个链接

English | 简体中文


Vue3 单页应用导航管理器,像原生 app 一样管理页面栈而不是销毁。

Example

预览

示例源码

功能特性

  • 🐉 在 vue-router 上扩展,原有导航逻辑不变
  • push或者forward的时候重新渲染页面,Stack 中会存储新渲染的页面
  • 🏆back或者go(负数)的时候先前的页面不会重新渲染,而是从 Stack 中读取,并且这些页面保留着先前的内容状态,例如表单内容,滚动条滚动的位置等
  • 🏈back或者go(负数)的时候会把不用的页面从 Stack 中移除
  • 🎓replace会更新 Stack 中当前页面
  • 🎉 回退到之前页面的时候有 activated 钩子函数触发
  • 🚀 支持浏览器的后退,前进事件
  • 🐰 提供路由方向的变化,并且可以在前进和后退的时候添加不同的动画

和 KeepAlive 的区别

  • 🌱 VuePageStack 不提供 include excludemax 参数,因为 VuePageStack 想要实现的是一个完整的页面栈管理,只能按照顺序进出
  • 🪁 KeepAlive 缓存过页面之后会一直缓存这个页面,VuePageStack 会根据页面栈的层级而自助销毁多余的页面
  • 🧬 KeepAlive 进入(不是返回)相同的路由页面,会继续复用以前缓存的页面,而 VuePageStack 会重新渲染页面

安装和用法

安装

pnpm install vue-page-stack

使用

import { createApp } from 'vue';
import { VuePageStackPlugin } from 'vue-page-stack';

const app = createApp(App);

// router is necessary
app.use(VuePageStackPlugin, { router });
// App.vue
<template>
  <router-view v-slot="{ Component }">
    <vue-page-stack @back="onBack" @forward="onForward">
      <component :is="Component" :key="$route.fullPath"></component>
    </vue-page-stack>
  </router-view>
</template>

<script setup>
const onBack = () => {
  console.log('back');
};

const onForward = () => {
  console.log('forward');
};
</script>

API

注册插件

使用之前需要注册插件

import { VuePageStackPlugin } from 'vue-page-stack';

//...
app.use(VuePageStackPlugin, { router });

Options 说明:

Attribute Description Type Accepted Values Default
router vue-router instance Object vue-router instance -

前进和后退

如果想在页面前进或者后退的时候添加一些事件,可以通过组件的 back 事件和 forward 事件进行处理

// App.vue
<template>
  <router-view v-slot="{ Component }">
    <vue-page-stack @back="onBack" @forward="onForward">
      <component :is="Component" :key="$route.fullPath"></component>
    </vue-page-stack>
  </router-view>
</template>

<script setup>
const onBack = () => {
  console.log('back');
};

const onForward = () => {
  console.log('forward');
};
</script>

example

相关说明

更新日志

主要的更新日志在 release notes

原理

获取当前页面实例部分参考了Vue源码中KeepAlive的部分

感谢

这个插件同时借鉴了vue-navigationvue-nav,很感谢他们给的灵感。

Contributors ✨

Thanks goes to these wonderful people (emoji key):

hezf
hezf

🎨
李娜
李娜

📖
余小磊
余小磊

💻
yellowbeee
yellowbeee

💻
MIT License Copyright (c) 2019-2024 hezf Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

vue-page-stack 是一个 Vue 单页应用导航管理器 展开 收起
README
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/mirrors/vue-page-stack.git
git@gitee.com:mirrors/vue-page-stack.git
mirrors
vue-page-stack
vue-page-stack
master

搜索帮助