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 🙏

© 2024 – Pkg Stats / Ryan Hefner

keep-alive-router-view

v1.2.8

Published

Extend vue2 keep-alive and router-view, add the function of automatically judging whether to use the cache.

Downloads

78

Readme

keep-alive-router-view 中文

Extend vue2 keep-alive and router-view, add the function of automatically judging whether to use the cache.

You can use vite-app-pro cli to create template project,keep-alive-router-view was built in project,convenient experience and use。

Support for vue3 Click here

The background of the problem

If the page uses keep-alive and router-view, the advantage is that the operation state of the previous step is quickly restored when the next page operation returns, and this experience is very good.

But it also brings problems.

When the user enters the page from the navigation menu or breadcrumb, a brand new page is needed, but the cached page is actually used, and this result is not what we want.

keep-alive-router-view solves this problem.

It uses the cache when you operate $router.back and $router.go to return the page by default, and $router.push and $router.replace do not use the cache by default.

Install

npm i keep-alive-router-view

Steps for usage

First: import and register component

import KeepAliveRouterView from 'keep-alive-router-view';

Vue.use(KeepAliveRouterView);

Second: use keep-alive-router-view component replace keep-alive and router-view components

keep-alive-router-view encapsulates keep-alive and router-view internally,

so you only need to write the keep-alive-router-view component element.

The cache attribute is used to cache the use of page caching.

Example1
<-- Recommend -->
<keep-alive-router-view :cache="$route.meta.cache" />
Example2
<-- Use cache for items with tab manager -->
<keep-alive-router-view
    :cache="!$route.meta || !$route.meta.noCache"
    :defaultCache="true" />

Third: must use the method of the vue-router instance. Only after $router.go and $router.back are called, the cached page is used.

keep-alive-router-view properties descriptions

| property | description | type | option | default | | --- |-----------------------------------------------------------| --- | --- |---------| | cache | whether to cache page | Boolean | true/false | false | | defaultCache | $router.push、$router.replace and $router.go(value is greater than 0) parameter cache will use the value | Boolean | true/false | false | | name | router-view name | String | - | - | | include | only components with matching names will be cached | RegExp | - | - | | exclude | any component whose name matches will not be cached | RegExp | - | - | | max | maximum number of component instances that can be cached | Number | - | - |

vue-router interface extensions

$router.push/replace

The page displayed by the push/replace interface does not use the cache function by default. If you need to use it, configure cache to true Note that defaultCache can change the default cache

// disable cache
this.$router.push({
  name: 'list',
});
this.$router.replace({
  name: 'list',
});

// use cache
this.$router.push({
  name: 'list',
  cache: true
});
this.$router.replace({
  name: 'list',
  cache: true
});

$router.back/forward/go

The page displayed by the back/forward/go interface uses the cache function by default. If not use cached page, configure cache to false

// defaut use cache
this.$router.back();
this.$router.forward();
this.$router.go(1);

// disable cache
this.$router.back({cache: false});
this.$router.forward({cache: false});
this.$router.go(1, {cache: false});

keep-alive-router-view attribute cache and $router interface parameter cache values determine whether the page uses cache.

| keep-alive-router-view cache | $router cache | Whether to use cache | |------------------|-----------------|----------------------| | true | true | Yes | | true | false | Not | | false | true | Not | | false | false | Not | The page cache takes effect when both cache values are true. None of the others use cached pages.