Demo: View example
Install
npm i feb-alive -S
<script src="./dist/feb-alive.browser.js"></script>
On the browser side, you can use the variable window.$febAlive
to access the package object
Usage example
import febAlive from 'feb-alive'
import Router from 'vue-router'
// Rewrite history before router instantiation
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 Support routing nesting, same as keep-alive
<template>
<x-header />
<feb-alive>
<router-view></router-view>
</feb-alive>
</template>
Vue.use(febAlive, options)
属性 | 类型 | 介绍 |
---|---|---|
router | VueRouter | Route instance |
keyName | string | Primary key used to cache pages,default: 'key' |
isServer | boolean | Whether it is server-side rendering mode,default: false |
maxPage | number | Maximum number of cached pages with feb-alive,default: 10 |
beforeLocationChange | function | Intercept function before page jump |
beforeLocationChange(route, cb)
route
The route matched after executing $loaction.to or $loaction.replacecb(true)
Execute VueRouter single page jump, call router.push and router.repalce respectivelycb(false)
Perform location jump, call location.href and location.replace respectively
- disableCache:
boolean
Whether to turn off feb-alive cache,default: false
{
meta: {
disableCache: false
}
}
- Initialize the Histroy API, because vue-router will rewrite history.state, it must be called before VueRouter is instantiated
febAlive.resetHistory()
- When the plugin is installed, the
$location
object will be mounted on the Vue prototype, and all the Vue component instance can be accessed throughthis.$location
$location.to(location, [ native])
-
location:
string | object
The url that needs to be redirected can be an absolute path or a relative path. If native is false and the url is a relative path, the single-page route will be matched first, and location.replace will be used if it is not matched. -
native:
boolean
Whether to force the use of native location.href jump, 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
The url that needs to be redirected can be an absolute path or a relative path. If native is false and the url is a relative path, the single-page route will be matched first, and location.replace will be used if it is not matched. -
native:
boolean
Whether to force the use of native location.href jump, default:false
$location.go(n)
- same as
router.go(n)
$location.back()
- same as
router.back()
$location.forward()
- same as
router.forward()
feb-alive is licensed under the MIT License - see the LICENSE file for details.