当前位置: 首页 > news >正文

java电影资源网站开发网站流量排名

java电影资源网站开发,网站流量排名,做书评的网站有哪些,做设计的都用那些网站文章目录 路由器工作模式命名路由to的三种写法嵌套路由路由传参query参数params参数 路由的props配置replace 和 push编程式导航重定向 总结 路由器工作模式 history模式 优点:URL更加美观,不带有#,更接近传统的网站URL。 缺点:后…

文章目录

    • 路由器工作模式
    • 命名路由
    • to的三种写法
    • 嵌套路由
    • 路由传参
      • query参数
      • params参数
    • 路由的props配置
    • replace 和 push
    • 编程式导航
    • 重定向
  • 总结


路由器工作模式

  1. history模式

    优点:URL更加美观,不带有#,更接近传统的网站URL

    缺点:后期项目上线,需要服务端配合处理路径问题,否则刷新会有404错误。

    const router = createRouter({history:createWebHistory(), //history模式/******/
    })
    
  2. hash模式

    优点:兼容性更好,因为不需要服务器端处理路径。

    缺点:URL带有#不太美观,且在SEO优化方面相对较差。

    const router = createRouter({history:createWebHashHistory(), //hash模式/******/
    })
    

命名路由

routes:[{name:'zhuye',path:'/home',component:Home},{name:'xinwen',path:'/news',component:News,},{name:'guanyu',path:'/about',component:About}
]

to的三种写法

<!-- 第一种:to的字符串写法 -->
<router-link active-class="active" to="/home">Home</router-link><!-- 第二种:to的对象写法 -->
<router-link active-class="active" :to="{path:'/home'}">Home</router-link><!-- 第三种: -->
<router-link active-class="active" :to="{name:'zhuye'}">Home</router-link>

嵌套路由

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

  2. 配置路由规则,使用children配置项:

    const router = createRouter({history:createWebHistory(),routes:[{name:'xinwen',path:'/news',component:News,children:[{name:'xiang',path:'detail',component:Detail}]}]
    })
    export default router
    
  3. 跳转路由(记得要加完整路径):

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

路由传参

query参数

  1. 传递参数

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

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

params参数

  1. 传递参数

    <!-- 跳转并携带params参数(to的字符串写法) -->
    <RouterLink :to="`/news/detail/001/新闻001/内容001`"></RouterLink> //直接写要传送内容 需要提前在规则(router)中配置站位<!-- 跳转并携带params参数(to的对象写法) -->
    <RouterLink :to="{name:'xiang', //用name跳转params:{id:news.id,title:news.title,content:news.title}}"
    ></RouterLink>
    
  2. 接收参数:

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

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

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

路由的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}
}

replace 和 push

  1. 作用:控制路由跳转时操作浏览器历史记录的模式。

  2. 浏览器的历史记录有两种写入方式:分别为pushreplace

    • push是追加历史记录(默认值)。
    • replace是替换当前记录。
  3. 开启replace模式:

    <RouterLink replace .......>News</RouterLink>
    

编程式导航

路由组件的两个重要的属性:$route$router变成了两个hooks

import {useRoute,useRouter} from 'vue-router'const route = useRoute()
const router = useRouter()console.log(route.query)
console.log(route.parmas)
console.log(router.push)
console.log(router.replace)

重定向

  1. 作用:将特定的路径,重新定向到已有路由。

  2. 具体编码:

    {path:'/',redirect:'/about'
    }
    

总结

Vue 3.0的基本语法至此已经结束了,后面将会介绍pinia 和 组件通信。

http://www.mmbaike.com/news/55246.html

相关文章:

  • wordpress 调用文章id搜索引擎优化的五个方面
  • 做a动漫视频在线观看网站15个常见关键词
  • 怎么进入企业的网站百度的网址怎么写
  • 公司门户网站建设费计入什么科目网络营销的优势和劣势
  • 网站空间报价单百度官网认证免费
  • 搭建网站公司哪家好靠谱的代写平台
  • 网站建设要求营销策划方案案例范文
  • 建设美妆企业网站搜索引擎营销有哪些方式
  • wordpress 限时杭州seo博客
  • 郑州企业网站建设重庆网站推广联系方式
  • 公司做网站一般要多少钱上海百度seo牛巨微
  • 一级a做爰电影片免费网站社群营销怎么做
  • 莆田网站自助建站长沙网络推广公司
  • 优质的做网站网络营销毕业论文8000字
  • css模板网站苏州网络公司
  • 沈阳市国际旅行社电话seo搜索引擎优化工具
  • 固安做网站新闻发稿平台
  • 建设行业的门户网站谷歌google官网
  • 恩施网站定制免费的舆情网站入口在哪
  • 网站做302重定向会怎么样西安百度关键词优化排名
  • 站长广告联盟平台2021拉新推广佣金排行榜
  • 宝鸡手机网站开发全网整合营销公司
  • 溧阳住房和城乡建设局网站网络推广公司名字
  • wordpress for mac下载西安seo网站建设
  • 做网站公司300元钱百度竞价推广开户内容
  • 中国建设银行网站登录不上线上营销策划案例
  • 满山红网站建设品牌营销策划方案案例
  • 公司网站需要在公安局备案吗自动优化app
  • 建产品网站怎么做百度云搜索引擎入口手机版
  • 湛江网站建设在线seo工具