npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vue-router-cache-animate

v0.0.5

Published

Quickly customize caching and animation for vue-router.

Readme

vue-router-cache-animate

使用 vue 的 keep-alive 和 transition 组件对路由进行快捷的动画和缓存设置。

demo

demo

安装

npm i vue-router-cache-animate
yarn add vue-router-cache-animate

使用

main.js

import Vue from 'vue'
import router from './router'
import vueRouterCacheAnimate from 'vue-router-cache-animate'

// 提供的移动端 slide-left、slide-right 动画,也可以自定义
import 'vue-router-cache-animate/dist/css/animate.css'
Vue.use(vueRouterCacheAnimate, { router })

App.vue

<template>
  <div id="app">
    <vue-router-cache-animate :caches="caches" :transitions="transitions">
      <router-view />
    </vue-router-cache-animate>
  </div>
</template>
<script>
export default {
  data() {
    return {
      caches: [
        {
          // 路由 name 和路由组件的 name(需保证相同)
          names: {
            include: ['A'],
            exclude: undefined
          },
          // 在哪些路由上被缓存
          cachedOn: {
            include: ['B', 'C'],
            exclude: undefined
          }
        }
      ],
      transitions: [
        {
          name: 'slide-left',
          reverseName: 'slide-right',
          from: {
            // 路由 name
            include: ['A'],
            exclude: undefined
          },
          to: {
            // 路由 name
            include: ['B', 'C'],
            exclude: undefined
          }
        }
      ]
    }
  }
}
</script>

Props

caches

缓存设置。

  • 类型:Array

  • 默认值:

    {
      names: {},
      cachedOn: {}
    }

    默认缓存所有路由。

  • 示例:

    export default {
      data() {
        return {
          caches: [
            {
              // 路由 name 和路由组件的 name(需保证相同)
              names: {
                include: ['A']
                // exclude: []
              },
              // 在'B', 'C'路由上缓存路由组件 A
              cachedOn: {
                include: ['B', 'C']
                // exclude: []
              }
            },
            {
              names: {
                include: ['B']
              },
              // 在 'C' 路由上缓存路由组件 B
              cachedOn: {
                include: ['C']
              }
            }
          ]
        }
      }
    }

    除了使用 include 包含,还可以使用 exclude 排除。

transitions

动画设置。

  • 类型:Array

  • 默认值:[]

  • 示例:

    export default {
      data() {
        return {
          transitions: [
            {
              // transition 组件的 name 选项
              // 从 'A' 路由到 'B', 'C' 路由使用 'slide-left' 动画
              name: 'slide-left',
              // 'B', 'C' 路由到 'A', 使用 'slide-right' 动画
              reverseName: 'slide-right',
              from: {
                // 路由 name
                include: ['A']
                // exclude: []
              },
              to: {
                // 路由 name
                include: ['B', 'C']
                // exclude: []
              }
            }
          ]
        }
      }
    }

noCacheOnBack

后退时,是否缓存路由。

  • 类型:Boolean
  • 默认值:false

后退的情况:

  1. 浏览器后退按钮。
  2. history.go(-n) 或者 history.back()
  3. router.go(-n) 或者 router.back()
  4. 其他操作浏览器历史记录倒退的方法。

实现像手机端 app 一样前进刷新,后退缓存的效果。

路由切换时,会自动缓存前一个路由。当 后退 时,不缓存当前路由,这样当再次前往该路由时,会重新生成。

export default {
  data() {
    return {
      noCacheOnBack: true
    }
  }
}

当使用 history.pushState(state, title, path)history.replaceState 时,需要设置 state 为一个对象,并提供一个唯一 key 属性。例如:

history.pushState(
  {
    key: new Date() + Math.random()
  },
  title,
  path
)

这个 key 会被用来判断浏览器是前进还是后退。