0.0.18 • Published 2 years ago

vue3-history v0.0.18

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

vue3-history

记录vue3 实例中 路由变化 主要用于当前网站返回按钮的功能. 会在app全局注入$history 字段 ex: 1. 用户直接访问非首页url. 左上角 返回按钮用来判断当前实例访问记录, 如果当前访问记录为1, 那么返回按钮直接push home 页面. 如果访问记录>1 则直接router.back()

Install

pnpm add vue3-history

Api

optionsdesctype
routervue router 实例Router
debug是否打印堆栈信息boolean
onRouteChange路由变化触发(v:any) => void
onQuit即将退出app触发,即current = 0 时,history.back 会触发() => void

Useage

// main.ts 
import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import { createHistory } from "vue3-history";

// core 
const Vue3History = createHistory({
  router,
  debug: true,
  onRouteChange: (v: any) => {
    console.log("onRouteChange", v);
  },
  onQuit() {
    alert('已经到第一页了')
  },
})

createApp(App).use(router).use(Vue3History).mount("#app");
<script setup lang='ts'>
import { useRouter } from 'vue-router'
import { getCurrentInstance } from 'vue'
/** 两种用法
    1. 从getCurrentInstance 中获取
    2. template 中可直接通过$history 使用
*/
const { proxy } = getCurrentInstance()
const history = proxy?.$history
    
</script>

<template>
	<div>
    堆栈信息: {{$history.stack}}
    当前路由下标: {{$history.current}}
    </div>
</template>
0.0.11

2 years ago

0.0.12

2 years ago

0.0.13

2 years ago

0.0.14

2 years ago

0.0.15

2 years ago

0.0.9

2 years ago

0.0.16

2 years ago

0.0.8

2 years ago

0.0.17

2 years ago

0.0.18

2 years ago

0.0.5

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago