当前位置: 首页> 汽车> 报价 > 常见的网页布局结构有哪些_磁力搜索神器_网络营销师_网站设计制作一条龙

常见的网页布局结构有哪些_磁力搜索神器_网络营销师_网站设计制作一条龙

时间:2025/8/23 8:41:52来源:https://blog.csdn.net/u013473447/article/details/144722458 浏览次数: 0次
常见的网页布局结构有哪些_磁力搜索神器_网络营销师_网站设计制作一条龙

1 【嵌套路由】

 (1)编写`News`的子路由:`Detail.vue`

 (2)配置路由规则,使用`children`配置项:

   const router = createRouter({history:createWebHistory(),routes:[{name:'zhuye',path:'/home',component:Home},{name:'xinwen',path:'/news',component:News,children:[{name:'xiang',path:'detail',component:Detail}]},{name:'guanyu',path:'/about',component:About}]})export default router

 (3) 跳转路由(记得要加完整路径):

   <router-link to="/news/detail">xxxx</router-link><!-- 或 --><router-link :to="{path:'/news/detail'}">xxxx</router-link>

  (4)记得去`Home`组件中预留一个`<router-view>`

 

 <template><div class="news"><nav class="news-list"><RouterLink v-for="news in newsList" :key="news.id" :to="{path:'/news/detail'}">{{news.name}}</RouterLink></nav><div class="news-detail"><RouterView/></div></div></template>

2. 【路由传参】

   query参数

 (1). 传递参数

 <!-- 跳转并携带query参数(to的字符串写法) --><router-link to="/news/detail?a=1&b=2&content=欢迎你">跳转</router-link><!-- 跳转并携带query参数(to的对象写法) --><RouterLink:to="{//name:'xiang', //用name也可以跳转path:'/news/detail',query:{id:news.id,title:news.title,content:news.content}}">{{news.title}}</RouterLink>

(2). 接收参数:

      import {useRoute} from 'vue-router'const route = useRoute()// 打印query参数console.log(route.query)

params参数

 (1). 传递参数

     

<!-- 跳转并携带params参数(to的字符串写法) --><RouterLink :to="`/news/detail/001/新闻001/内容001`">{{news.title}}</RouterLink><!-- 跳转并携带params参数(to的对象写法) --><RouterLink:to="{name:'xiang', //用name跳转params:{id:news.id,title:news.title,content:news.title}}">{{news.title}}</RouterLink>

(2). 接收参数:

      import {useRoute} from 'vue-router'const route = useRoute()// 打印params参数console.log(route.params)

备注1:传递`params`参数时,若使用`to`的对象写法,必须使用`name`配置项,不能用`path`。

 备注2:传递`params`参数时,需要提前在规则中占位。

3. 【路由的props配置】

作用:让路由组件更方便的收到参数(可以将路由参数作为`props`传给组件)

{name:'xiang',path:'detail/:id/:title/:content',component:Detail,// props的对象写法,作用:把对象中的每一组key-value作为props传给Detail组件// props:{a:1,b:2,c:3},// props的布尔值写法,作用:把收到了每一组params参数,作为props传给Detail组件// props:true// props的函数写法,作用:把返回的对象中每一组key-value作为props传给Detail组件props(route){return route.query}}

关键字:常见的网页布局结构有哪些_磁力搜索神器_网络营销师_网站设计制作一条龙

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: