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

feb-alive

v2.1.0

Published

A Vue.js plugins

Downloads

6

Readme

feb-alive 页面级缓存解决方案

English Document

社区文章

Vue页面级缓存解决方案feb-alive (上)

Vue页面级缓存解决方案feb-alive (下)

demo: 查看示例

image

安装

NPM

npm i feb-alive -S

Direct Download / CDN

<script src="./dist/feb-alive.browser.js"></script>

浏览器端可以使用变量window.$febAlive访问包对象

使用示例

import febAlive from 'feb-alive'
import Router from 'vue-router'

// 在router实例化之前重写history
febAlive.resetHistory()

const router = new Router(options)

Vue.use(febAlive, { router })
// App.vue
<template>
  <div id="app">
    <feb-alive>
      <router-view></router-view>
    </feb-alive>
  </div>
</template>
// Home.vue 支持路由嵌套, 同keep-alive
<template>
  <x-header />
  <feb-alive>
    <router-view></router-view>
  </feb-alive>
</template>

Vue.use(febAlive, options)

options

| 属性 | 类型 | 介绍 | | - | - | - | | router | VueRouter | 路由实例 | | keyName | string | 用于缓存页面的主键,default: 'key' | | isServer | boolean | 是否是服务端渲染模式,default: false | | maxPage | number | 每个feb-alive的缓存最大页数,default: 10 | | beforeLocationChange | function | 页面跳转前拦截函数 |

beforeLocationChange(route, cb)

  • route 调用$loaction.to或者$loaction.replace后所匹配到的路由组件
  • cb(true) 进行VueRouter单页跳转,分别调用router.push和router.repalce
  • cb(false) 进行location跳转,分别调用location.href和location.replace

路由meta配置

  • disableCache: boolean 是否关闭feb-alive缓存,default: false
{
  meta: {
    disableCache: false
  }
}

静态方法

resetHistory

  • 初始化 Histroy API,由于vue-router会重写history.state,所以必须在VueRouter实例化之前调用
febAlive.resetHistory()

Vue原型方法

$location

  • 插件在install时,会在Vue的原型上挂载$location对象,所有vue组件实例中都可以通过this.$location访问到

$location.to(location, [ native])

  • location: string | object 需要跳转的url,可以是绝对路径也可以是相对路径,如果native是false且url是相对路径则优先匹配单页路由,若未匹配到则进行location.href跳转
  • native: boolean 是否强制使用原生location.href跳转, default: false
vm.$location.to('https://www.google.com',true)
vm.$location.to('/home')
vm.$location.to({
  path: '/home',
  query: {
    tag: 'wedoctor'
  }
})

$location.replace(url, [ native])

  • url: string 需要跳转的url,可以是绝对路径也可以是相对路径,如果native是false且url是相对路径则优先匹配单页路由,若未匹配到则进行location.replace跳转
  • native: boolean 是否强制使用原生location.replace跳转, default: false

$location.go(n)

  • 同router.go(n)

$location.back()

  • 同router.back()

$location.forward()

  • 同router.forward()

Licence

feb-alive is licensed under the MIT License - see the LICENSE file for details.