目录前置知识Intersection Observer Vue3指令周期 image对象思路完整代码总结前置知识Intersection Observer 浏览器提供api,用于检测目标元素和祖先元素
顺晟科技
2022-09-13 11:13:37
187
在我们做项目时肯定会有出现动态路由:
一个品种的商品页面会有同类不同样的商品就要在路由的后面加一个id;
Vue的路由id是这样添加的:
首先现在Index.js添加id
{ path: "/user/:id", component: User }
然后再绑定Id
<router-link :to="'/user/'+dataid" tag="button">用户</router-link>
我们怎么动态获取这个id呢?
this.$route.params.id
<router-link :to="{path:'/proflie',query:{name:'雷荣',height:1.88,age:18}}" tag="button">我的</router-link>
直接就改成这样,不用配置什么id
动态路由还是非常的简单的;接下来就是懒加载学习了
我们可以看官方文档怎么解释
就是说当我们打包时,所有的js都打包在一起,在页面加载的时候会显得更加的吃力,于是就想了一个办法可不可以在使用某个组件的时候就加载某个js,其他的不调用,“用时即加载”。
概念知道后,Vue怎么实现这个功能呢?
//直接懒加载 const User = () => import('../components/User.vue') const Home = () => import('../components/Home.vue') const About = () => import('../components/About.vue')
就是这么简单;直接将以前引用组件的地方改成这样就可以了
然后就是
上代码一看就知:
{ path: '/home', component: Home, children: [ { path: '/', redirect: 'message' }, { path: 'message', component: HomeMessage }, { path: 'news', component: HomeNews }
就是在主路由里添加children,注意:这里的path可以不用写‘/’
19
2022-10
19
2022-10
19
2022-10
23
2022-09
23
2022-09
23
2022-09