Giter VIP home page Giter VIP logo

vue-page-stack's Introduction

vue-page-stack

npm version

English | 简体中文


A Vue SPA navigation manager,cache the UI in the SPA like a native application, rather than destroy it.

Example

preview

demo code

Features

  • 🐉expanded on vue-router, the original navigation logic remains unchanged
  • ⚽When a page is re-rendered as a push or forward, the newly rendered page will be added to the Stack
  • 🏆back or go (negative) will not be re-rendered. Reading the previous page from the Stack,and will preserve the previous content state, such as the form content, the position of the scroll bar
  • 🏈back or go (negative) will remove unused pages from the Stack
  • 🎓replace will update the current page in the stack
  • 🎉activited hook function triggers when rolling back to the previous page
  • 🚀support for browser back, forward events
  • 🍕support for changes in response routing parameters, such as navigating from /user/foo to /user/bar, component instances are reused
  • 🐰provides routing direction changes, add different animations when entering or leaving

Installation and use

Installation

npm install vue-page-stack
# OR
yarn add vue-page-stack

use

import Vue from 'vue'
import VuePageStack from 'vue-page-stack';

// vue-router is necessary
Vue.use(VuePageStack, { router }); 
// App.vue
<template>
  <div id="app">
    <vue-page-stack>
      <router-view ></router-view>
    </vue-page-stack>
  </div>
</template>

CDN

<script src="https://unpkg.com/vue-page-stack/dist/vue-page-stack.js"></script>
Vue.use(VuePageStack.default, { router });

API

install

use Vue.use to install vue-page-stack

Vue.use(VuePageStack, options);
// example
Vue.use(VuePageStack, { router });

Options description:

Attribute Description Type Accepted Values Default
router vue-router instance Object vue-router instance -
name VuePageStack name String 'VuePageStack' 'VuePageStack'
keyName stack-key name String 'stack-key' 'stack-key'

you can customize VuePageStack's name and keyName

Vue.use(VuePageStack, { router, name: 'VuePageStack', keyName: 'stack-key' });

forward or backward

If you want to make some animate entering or leaving, vue-page-stack offers stack-key-dir to judge forward or backward.

// App.vue
$route(to, from) {
  if (to.params['stack-key-dir'] === 'forward') {
    this.transitionName = 'forward';
  } else {
    this.transitionName = 'back';
  }
}

example

Notes

keyName

Why is the parameter keyName added to the route? To support the browser's backward and forward events,this is important in webApp or wechat.

Principle

Getting the current page instance refers to the keep-alive section of Vue.

Thanks

The plug-in draws on both vue-navigation and vue-nav,Thank you very much for their inspiration.

vue-page-stack's People

Contributors

hezhongfeng avatar woshilina avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.