第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Vue-router中的scrollBehavior滾動屬性不支持二級路由?怎么配置才能起作用呢?

Vue-router中的scrollBehavior滾動屬性不支持二級路由?怎么配置才能起作用呢?

呼啦一陣風 2019-03-06 13:15:51
scrollBehavior (to, from, savedPosition) {  return { x: 0, y: 0 }}我的目的是切換路由后每次都滾動到頁面頂部但是這樣配置好像只對一級路由生效,像/page/1 -> /page/2 這樣二級路由的切換就不起作用了。。應該怎么處理呢
查看完整描述

1 回答

?
泛舟湖上清波郎朗

TA貢獻1818條經驗 獲得超3個贊

支持二級路由啊,我的代碼是這樣寫的。

router/index.js


const scrollBehavior = (to, from, savedPosition) => {

    if (savedPosition) {

        // savedPosition is only available for popstate navigations.

        return savedPosition;

    } else {

        const position = {}

            // new navigation.

            // scroll to anchor by returning the selector

        if (to.hash) {

            position.selector = to.hash

        }

        // check if any matched route config has meta that requires scrolling to top

        if (to.matched.some(m => m.meta.scrollToTop)) {

            // cords will be used if no selector is provided,

            // or if the selector didn't match any element.

            position.x = 0

            position.y = 0

        }

        // if the returned position is falsy or an empty object,

        // will retain current scroll position.

        return position;

    }

};


let router = new Router({

    mode: 'history',

    scrollBehavior,

    routes: [

        {

            path: '/detail/:id',

            name: 'Detail',

            component: Detail,

            meta: {

                scrollToTop: true

            }

        }

    ]

});


查看完整回答
反對 回復 2019-04-09
  • 1 回答
  • 0 關注
  • 717 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號