vue笔记

94 阅读1分钟

1.切换组件回到顶部

export default new VueRouter({
        routes: [
        ....配置路由内容
        ],
        crollBehavior (to, from, savedPosition) {
        // 路由切换,简单的让页面滚动到顶部      
        return { x: 0, y: 0 }
        }
})

2.去掉地址栏#

//配置路由
const routes= [
    ....配置路由内容
]

const router= new VueRouter({
        //去掉地址栏#
        mode: 'history',
        routes,
                // 路由切换,简单的让页面滚动到顶部
        scrollBehavior (to, from, savedPosition) {
                return { x: 0, y: 0 }
                },
})

export default router

3.Vue在刷新后引用的样式无效

解决:把所有的引用文件都转为绝对地址

<link rel="stylesheet" href="./static/css/scroll.css"> 
↓ 
<link rel="stylesheet" href="/static/css/scroll.css">