Code Monkey home page Code Monkey logo

vue-page-stack-router's Introduction

vue-page-stack-router

vue-page-stack-router 是一个 Vue.js 的页面栈路由管理器,支持 Vue 2 和 Vue 3

功能特性

  • 针对移动端 web 而设计
  • 类似原生 APP 应用,小程序应用的导航体验,即前进刷新后退不刷新
  • 保存滚动位置(默认为 true),在离开该页面时自动保存滚动位置,待返回后恢复保存的滚动位置

版本提示

你当前浏览的是 vue-page-stack-router 3.x 版本 的文档,适用于 Vue 3 开发。如果你在使用 Vue 2,请浏览 vue-page-stack-router@2 文档

🔥 例子

安装

# Vue 3 项目,安装
npm install vue-page-stack-router --save
# Vue 2 项目,安装
npm install vue-page-stack-router@2 --save

浏览器支持

vue-page-stack-router 3.x 支持现代浏览器以及 Chrome >= 51、iOS >= 10.0(与 Vue 3 一致)。

使用

main.js

import { createApp } from 'vue';
import App from './App.vue';
import { router } from './router';
import { createPageStackRouter } from 'vue-page-stack-router';

// app
const app = createApp(App);

// pageStackRouter
const pageStackRouter = createPageStackRouter({ router });

app.use(router);
app.use(pageStackRouter);
app.mount('#app');

App.vue

<template>
  <div id="app">
    <PageStackRouterView />
  </div>
</template>

routes.js

import { createRouter, createWebHashHistory } from "vue-router";

export const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: "/",
      redirect: "/home",
    },
    {
      path: "/home",
      name: "Home", // 与组件 name 保持一致
      component: () => import("@/views/home/index.vue"),
      meta: {
        title: "首页",
      },
    },
    {
      path: "/good/detail",
      name: "GoodDetail", // 与组件 name 保持一致
      component: () => import("@/views/good/detail.vue"),
      meta: {
        title: "商品详情",
      },
    },
  ],
});

API

VuePageStackRouter 插件参数说明:

参数 说明 类型 默认值
router vue-router 实例 object -
el Vue 应用实例挂载容器元素 string '#app'
max 最多可以缓存多少页面组件实例 number 10
disableSaveScrollPosition 禁用自动保存滚动位置 boolean false

配置路由元信息(可选)

可以根据业务需要,自定义配置路由的 meta 字段:

{
  path: '/login',
  name: 'login',
  component: () => import('@/views/login/index.vue'),
  meta: {
    title: '登录',
    // `keepAlive`字段,是否参与页面栈导航。默认全部参与
    keepAlive: true,
    // `scrollingElement`字段,手动指定页面内滚动容器元素。默认查询全部
    scrollingElement: [".list-scroller", ".header-bd-radio-group"],
    // `disableSaveScrollPosition`字段,禁用自动保存滚动位置。默认为 `false`
    disableSaveScrollPosition: false,
  },
},

使用注意

  1. 路由的name和组件的name都需要设置成一样,缓存才会生效。
  2. 只支持一级路由,不支持嵌套路由。
  3. 也可以去隔壁 v-shop qq群问

vue-page-stack-router's People

Contributors

joeshutt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vue-page-stack-router's Issues

ios长列表滚动位置无法缓存

<div class="keepA">
        <input type="text">
        <ul>
            <li class="li" @click="toNext(i)" v-for="i in 100">{{ i }}</li>
        </ul>
 </div>

ios真机调试时,长列表滚动后,没法缓存滚动的位置,会回到顶部。input的内容是正常缓存的。

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.