" 문을 사용합니다. 2. "this.$router.push()" 문을 사용합니다. 3. "this.$router. 4. "this.$router.go(n)" 문을 사용하십시오."/> " 문을 사용합니다. 2. "this.$router.push()" 문을 사용합니다. 3. "this.$router. 4. "this.$router.go(n)" 문을 사용하십시오.">

 >  기사  >  웹 프론트엔드  >  Vue 라우팅 점프 방법은 무엇입니까?

Vue 라우팅 점프 방법은 무엇입니까?

青灯夜游
青灯夜游원래의
2021-10-27 15:25:1342037검색

Jump 방법: 1. "1a2f917cffbb0e12bcc5e5e9f956021f" 문을 사용합니다. 2. "this.$router.push()" 문을 사용합니다. . $router.replace()" 문; 4. "this.$router.go(n)" 문을 사용합니다.

Vue 라우팅 점프 방법은 무엇입니까?

이 튜토리얼의 운영 환경: Windows 7 시스템, vue 버전 2.9.6, DELL G3 컴퓨터.

vue 점프를 라우팅하는 네 가지 방법(매개변수 사용)

1. router-link

1. 不带参数
 
<router-link :to="{name:&#39;home&#39;}"> 
<router-link :to="{path:&#39;/home&#39;}"> //name,path都行, 建议用name  
// 注意:router-link中链接如果是&#39;/&#39;开始就是从根路由开始,如果开始不带&#39;/&#39;,则从当前路由开始。
 
 
 
2.带参数
 
<router-link :to="{name:&#39;home&#39;, params: {id:1}}">  
 
// params传参数 (类似post)
// 路由配置 path: "/home/:id" 或者 path: "/home:id" 
// 不配置path ,第一次可请求,刷新页面id会消失
// 配置path,刷新页面id会保留
 
// html 取参  $route.params.id
// script 取参  this.$route.params.id
 
 
<router-link :to="{name:&#39;home&#39;, query: {id:1}}"> 
 
// query传参数 (类似get,url后面会显示参数)
// 路由可不配置
 
// html 取参  $route.query.id
// script 取参  this.$route.query.id

2 this.$router.push()(함수에서 호출됨)

1.  不带参数
 
this.$router.push(&#39;/home&#39;)
this.$router.push({name:&#39;home&#39;})
this.$router.push({path:&#39;/home&#39;})
 
 
 
2. query传参 
 
this.$router.push({name:&#39;home&#39;,query: {id:&#39;1&#39;}})
this.$router.push({path:&#39;/home&#39;,query: {id:&#39;1&#39;}})
 
// html 取参  $route.query.id
// script 取参  this.$route.query.id
 
 
 
3. params传参
 
this.$router.push({name:&#39;home&#39;,params: {id:&#39;1&#39;}})  // 只能用 name
 
// 路由配置 path: "/home/:id" 或者 path: "/home:id" ,
// 不配置path ,第一次可请求,刷新页面id会消失
// 配置path,刷新页面id会保留
 
// html 取参  $route.params.id
// script 取参  this.$route.params.id
 
 
 
4. query和params区别
query类似 get, 跳转之后页面 url后面会拼接参数,类似?id=1, 非重要性的可以这样传, 密码之类还是用params刷新页面id还在
 
params类似 post, 跳转之后页面 url后面不会拼接参数 , 但是刷新页面id 会消失

3. this.$router.replace() (사용방법은 위와 동일, push)

4. this.$router.go(n)

this.$router.go(n)
向前或者向后跳转n个页面,n可为正整数或负整数

ps: 차이점

  • this.$ router.push
    는 지정된 URL 경로로 점프하고 기록 스택에 기록을 추가합니다. 뒤로 클릭하면 이전 페이지로 돌아갑니다.

  • this.$router.replace
    는 지정된 URL 경로로 점프합니다. , 그러나 기록에는 스택에 기록이 없습니다. 돌아가기를 클릭하면 이전 페이지로 이동합니다(즉, 현재 페이지를 직접 대체합니다)

  • this.$router.go(n)
    앞으로 또는 뒤로 이동합니다. n번 페이지, n은 양수 또는 음수일 수 있습니다

관련 권장 사항: "vue.js tutorial"

위 내용은 Vue 라우팅 점프 방법은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.