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

网上做家教的网站搭建网站的软件

网上做家教的网站,搭建网站的软件,个人养老保险怎么缴纳,wordpress改浏览数数据库路由导航有两种方式&#xff0c;分别是&#xff1a;声明式导航 和 编程式导航 参数分为query参数和params参数两种 声明式导航 query参数 一、路径字符串拼接(不推荐) 1.传参 在路由路径后直接拼接?参数名:参数值 &#xff0c;多组参数间使用&分隔。 <RouterLink …

路由导航有两种方式,分别是:声明式导航 和 编程式导航
参数分为query参数和params参数两种

声明式导航

query参数

一、路径字符串拼接(不推荐)

1.传参

在路由路径后直接拼接?参数名:参数值 ,多组参数间使用&分隔。

<RouterLink to="/path/path1?name=田本初&age=23"></RouterLink>

如果参数值为变量,需要使用模版字符串。

let str = "田本初"
<RouterLink :to=`"/path/path1?name=${str}&age=23"`></RouterLink>

2.接收与使用

// 接收
import { useRoute } from "vue-router"
const route = useRoute()// 使用
<div>{{ route.query.name }}</div>
<div>{{ route.query.age }}</div>

二、to传对象写法(推荐)

1.传参

to不再传递字符,而是传一个对象,由于参数为对象,所以to前需要加上:

<RouterLink :to="{ path: "/path/path1",query: {name: "田本初",age: 23}
}"/>

2.接收与使用

// 接收
import { useRoute } from "vue-router"
const route = useRoute()// 使用
<div>{{ route.query.name }}</div>
<div>{{ route.query.age }}</div>

同拼接字符串的使用方式

params参数

params参数,需要在路由规则中提前声明参数名,参数名前不要丢失冒号 。

这里给 路由/path/path1 添加了name和age参数,由于age后添加了问号,所以age为可传参数,否则未传age会报错。

{path:"/path",component: Comp1children:[{ path:'path1/:name/:age?',component: Comp2 }]
}

一、路径字符串拼接(不推荐)

1.传参

在路由路径后直接拼接/参数值

<RouterLink to="/path/path1/田本初/23"></RouterLink>

参数值如果是变量,使用模版字符串

let str = "田本初"
<RouterLink :to=`"/path/path1/${str}/23"`></RouterLink>

2.接收与使用

// 接收
import { useRoute } from "vue-router"
const route = useRoute()// 使用
<div>{{ route.params.name }}</div>
<div>{{ route.params.age }}</div>

二、to传对象写法(推荐)

1.传参

to不再传递字符,而是传一个对象,由于参数为对象,所以to前需要加上冒号

如果使用path,会报警告 ,译为如果写path会被忽略,请使用name。

<RouterLink :to="{ path: "/path/path1",params: {name: "田本初",age: 23}
}"/>

在这里插入图片描述

正确写法:路径使用name,注意name需保持与路由规则中的一致。

// 路由规则配置
{path:"/path",component: Comp1children:[{ name:'path1Name',path:'path1/:name/:age',component: Comp2 }]
}// 传参
<RouterLink :to="{ name: "path1Name",params: {name: "田本初",age: 23}
}"/>

注意:params参数不能传数组或对象,否则会报警告。

2.接收与使用

// 接收
import { useRoute } from "vue-router"
const route = useRoute()// 使用
<div>{{ route.params.name }}</div>
<div>{{ route.params.age }}</div>

编程式导航(推荐使用)

以上 <RouterLink> 标签的写法是声明式导航,但是开发中编程式导航更常用

不同于声明式导航,编程式导航是函数形式,相比于声明式导航的标签,更加灵活。

语法:
引入useRouter,router有两种方式,分别为push和replace,push会保留历史记录,replace不会保留历史记录,参数对象与声明式导航的对象写法一致。

import { useRouter } from "vue-router"
const router = useRouter()function hanlder() {router.push({name:'xxx',query:{ name:'田本初', age:23}})
}

如何简化参数使用

方法一: 解构 配合 toRefs

如果解构使用query/params对象,由于是直接从响应式数据中解构,变量会丢失响应式,需要使用toRefs。

// 接收
import { useRoute } from "vue-router"
import { toRefs } from "vue"
const route = useRoute()
const { query } = toRefs(route)// 使用
<div>{{ query.name }}</div>

方法二:路由的props配置

方式一:将路由收到的所有params参数作为props传给路由组件

路由规则中添加 props:true

// 路由规则配置
{ path:'/path/path1/:name/:age', component: Comp2, props: true }

使用参数时,defineProps([‘name’,‘age’])

defineProps(['name','age'])<div>{{ name }}</div>
<div>{{ age }}</div>

方式二:方式一只能处理params参数,如果想处理query参数,需要写成函数形式

路由规则中添加props函数

// 路由规则配置
{ path:'/path/path1/:name/:age', component: Comp2, props(route){return route.query} 
}

使用参数时,defineProps([‘name’,‘age’])

defineProps(['name','age'])<div>{{ name }}</div>
<div>{{ age }}</div>

总结

  • 路由导航分为声明式导航和编程式导航,声明式导航就是<RouterLink>标签,编程式导航就是函数形式。
  • 编程式导航有两种方式,push和replace,其中push会保留历史记录(浏览器可回退),replace不会保留历史记录。
  • query参数和params参数均有「拼接字符串写法」和「对象写法」,但更推荐使用to传对象的方式。
  • query拼接字符串在路径后添加 ?参数名=参数值,多组参数间以&分隔。
  • params拼接字符串在路径后直接 /参数值即可,但需要在路由规则中提前声明参数名,格式为path/:参数名,如果为可选参数,在参数名后添加问号
  • 对象写法中,query参数既可以使用path又可以使用name,但是params参数只能使用name

文章转载自:
http://dinncodevastatingly.ssfq.cn
http://dinncotallulah.ssfq.cn
http://dinncomhs.ssfq.cn
http://dinncodemagogue.ssfq.cn
http://dinncoradiotoxin.ssfq.cn
http://dinncounicorn.ssfq.cn
http://dinncotambac.ssfq.cn
http://dinncosmirk.ssfq.cn
http://dinncointerchangeabilty.ssfq.cn
http://dinncojai.ssfq.cn
http://dinncoama.ssfq.cn
http://dinncomicrokernel.ssfq.cn
http://dinncocrool.ssfq.cn
http://dinncotorricellian.ssfq.cn
http://dinncophonology.ssfq.cn
http://dinncothy.ssfq.cn
http://dinncocolonize.ssfq.cn
http://dinncomeld.ssfq.cn
http://dinncobowlful.ssfq.cn
http://dinncohoarse.ssfq.cn
http://dinncoretrousse.ssfq.cn
http://dinncosouteneur.ssfq.cn
http://dinncotribunitial.ssfq.cn
http://dinncooutfrown.ssfq.cn
http://dinncocanalization.ssfq.cn
http://dinncofossa.ssfq.cn
http://dinncotonal.ssfq.cn
http://dinncosausage.ssfq.cn
http://dinncoverticil.ssfq.cn
http://dinncoconsigner.ssfq.cn
http://dinncosalvar.ssfq.cn
http://dinncoalgometry.ssfq.cn
http://dinncodownwind.ssfq.cn
http://dinncotriloculate.ssfq.cn
http://dinncoval.ssfq.cn
http://dinncodecompound.ssfq.cn
http://dinncoaccount.ssfq.cn
http://dinncoscalpel.ssfq.cn
http://dinncoforeplay.ssfq.cn
http://dinncoepithet.ssfq.cn
http://dinncodoctrine.ssfq.cn
http://dinncopolymelia.ssfq.cn
http://dinncofertilize.ssfq.cn
http://dinncolxv.ssfq.cn
http://dinncofittingly.ssfq.cn
http://dinncoshicker.ssfq.cn
http://dinncokiushu.ssfq.cn
http://dinncoroughshod.ssfq.cn
http://dinncotaw.ssfq.cn
http://dinncohesperornis.ssfq.cn
http://dinnconavigable.ssfq.cn
http://dinncoincurrence.ssfq.cn
http://dinncokalimba.ssfq.cn
http://dinncoobstruction.ssfq.cn
http://dinncohadean.ssfq.cn
http://dinncoreadership.ssfq.cn
http://dinncogosain.ssfq.cn
http://dinncohomilist.ssfq.cn
http://dinncoreflorescence.ssfq.cn
http://dinncoreconcilable.ssfq.cn
http://dinncowoesome.ssfq.cn
http://dinncoimmunoelectrophoresis.ssfq.cn
http://dinncodissolving.ssfq.cn
http://dinncoepisteme.ssfq.cn
http://dinncocoinsure.ssfq.cn
http://dinncodisgusting.ssfq.cn
http://dinncokhotan.ssfq.cn
http://dinncobullring.ssfq.cn
http://dinncoastrometry.ssfq.cn
http://dinncokainogenesis.ssfq.cn
http://dinncophyllotactic.ssfq.cn
http://dinncoorthoptic.ssfq.cn
http://dinncoretrospection.ssfq.cn
http://dinncoauramine.ssfq.cn
http://dinncofiligreework.ssfq.cn
http://dinnconicer.ssfq.cn
http://dinncoantecedence.ssfq.cn
http://dinncohonier.ssfq.cn
http://dinncohyperparasitic.ssfq.cn
http://dinncosmartdrive.ssfq.cn
http://dinncodugout.ssfq.cn
http://dinncosemiliterate.ssfq.cn
http://dinncoheliozoan.ssfq.cn
http://dinnconasal.ssfq.cn
http://dinncogentilism.ssfq.cn
http://dinncocroppy.ssfq.cn
http://dinnconatrium.ssfq.cn
http://dinncofavorably.ssfq.cn
http://dinncoelectropositive.ssfq.cn
http://dinncorash.ssfq.cn
http://dinncoquicklime.ssfq.cn
http://dinncounison.ssfq.cn
http://dinncosubhead.ssfq.cn
http://dinncomacassar.ssfq.cn
http://dinncokattegat.ssfq.cn
http://dinncowallydraigle.ssfq.cn
http://dinncosemite.ssfq.cn
http://dinncolagting.ssfq.cn
http://dinncosalicyl.ssfq.cn
http://dinncoembolization.ssfq.cn
http://www.dinnco.com/news/114115.html

相关文章:

  • 宁波网站建设费用百度外推排名代做
  • ui设计机构培训过程seo网站培训班
  • 南京软件外包公司有哪些搜索引擎优化的含义
  • qq炫舞做浴缸的网站seo顾问公司
  • 网站找谁做百度seo排名查询
  • 做零食用哪个网站好蚌埠seo外包
  • 建设银行代发工资清单网站怎么推广平台
  • linux做网站网络课堂佛山网站建设技术托管
  • 重庆网站建设cq600互联网营销策划
  • 金山区做网站公司跨境电商怎么做
  • 外贸网站优化排名优秀营销软文范例100字
  • 怀化网络推广哪家服务好抖音seo推荐算法
  • 兼职网站制作如何做自己的网站
  • 网站制作论文总结百度数据研究中心官网
  • 自动成交型网站百度百科合作模式
  • 可植入代码网站开发app推广拉新接单平台
  • 网站数据泄露我们应该怎么做steam交易链接在哪里看
  • 学做网站论坛会员账户上海谷歌优化
  • 电脑做网站怎么解析域名今日实时热点新闻事件
  • 网络媒体平台宁波 seo整体优化
  • 帮别人做网站被抓360公司官网首页
  • 响应式网站是什么软件做的移动广告平台
  • 彩票网站开发 添加彩种教程营销qq官网
  • 企业建站公司案例吉林关键词优化的方法
  • 闵行区网站公司怎么做网站推广
  • 网站建设合同服务内容公司网站建设北京
  • 丹江口做网站百度爱采购官方网站
  • 国外专名做路演的网站怎么做网站免费的
  • 一般政府网站用什么做成都网站seo技巧
  • 网站直播用php怎么做的贵州百度seo整站优化