用指令管理vue滚动状态以及滚动条复原,让你为所欲为。

688 阅读1分钟

vue-rescroll 是一款滚动状态管理指令化的插件。

install
npm install vue-rescroll --save

全局注册/Global registration (main.js)

import VueRescroll from 'vue-rescroll';
Vue.use(VueRescroll);

局部注册/Partial registration (*.vue)

import { directive } from 'vue-rescroll';
directives: {
    'rescroll': directive
}

*.vue

使用默认配置/use default config
<div v-rescroll="{name: 'A unique marker'}"></div>

参数配置/Parameter configuration

key require value type discribe
name string 用来保存滚动状态的key值
type 'default'/'window' string 滚动类型(局部,全局)
storageMode 'default'/'localstorage' string 滚动状态保存方式
domType 'default'/'tab' string 是否为tab切换组件
<div
    v-rescroll="{
        name: `${id}-scroll`,
        type: 'window',
        storageMode: 'localstorage'
    }"
     ></div>

tips

页面不要使用keep-alive缓存,那样的话,钩子函数不会触发。
Don't use keep-alive caching for your pages. In that case, the hook function won't trigger

使用vuex缓存数据/use vuex

async created () {
    if (hasData) return hasData;
    return await this.getData();
}

必须要每次刷新的页面/must refreshed

async created () {
    openLoading();
    await this.getData();
    closeLoading();
}

github地址,觉得有用,欢迎start,欢迎一起讨论。
详细描述各种现象博客地址