欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue路由跳轉(zhuǎn)傳參數(shù)的方法

 更新時(shí)間:2019年05月06日 15:50:11   作者:帥阿星  
這篇文章主要介紹了vue路由跳轉(zhuǎn)傳參數(shù)的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

vue中路由跳轉(zhuǎn)傳參數(shù)有多種,自己常用的是下面的幾種

  1. 通過router-link進(jìn)行跳轉(zhuǎn)
  2. 通過編程導(dǎo)航進(jìn)行路由跳轉(zhuǎn)

 1. router-link

<router-link 
 :to="{
  path: 'yourPath', 
  params: { 
   name: 'name', 
   dataObj: data
  },
  query: {
   name: 'name', 
   dataObj: data
  }
 }">
</router-link>

 1. path -> 是要跳轉(zhuǎn)的路由路徑,也可以是路由文件里面配置的 name 值,兩者都可以進(jìn)行路由導(dǎo)航
 2. params -> 是要傳送的參數(shù),參數(shù)可以直接key:value形式傳遞
 3. query -> 是通過 url 來傳遞參數(shù)的同樣是key:value形式傳遞

 // 2,3兩點(diǎn)皆可傳遞

2. $router方式跳轉(zhuǎn)

// 組件 a
<template>
 <button @click="sendParams">傳遞</button>
</template>
<script>
 export default {
 name: '',
 data () {
  return {
  msg: 'test message'
  }
 },
 methods: {
  sendParams () {
  this.$router.push({
   path: 'yourPath', 
   name: '要跳轉(zhuǎn)的路徑的 name,在 router 文件夾下的 index.js 文件內(nèi)找',
   params: { 
    name: 'name', 
    dataObj: this.msg
   }
   /*query: {
    name: 'name', 
    dataObj: this.msg
   }*/
  })
  }
 },
 computed: {

 },
 mounted () {

 }
 }
</script>
<style scoped></style>
----------------------------------------
// 組件b
<template>
 <h3>msg</h3>
</template>
<script>
 export default {
 name: '',
 data () {
  return {
  msg: ''
  }
 },
 methods: {
  getParams () {
  // 取到路由帶過來的參數(shù) 
  let routerParams = this.$route.params.dataobj
  // 將數(shù)據(jù)放在當(dāng)前組件的數(shù)據(jù)內(nèi)
  this.msg = routerParams
  }
 },
 watch: {
 // 監(jiān)測路由變化,只要變化了就調(diào)用獲取路由參數(shù)方法將數(shù)據(jù)存儲本組件即可
  '$route': 'getParams'
 }
 }
</script>
<style scoped></style>

這次項(xiàng)目就遇到了這些問題, 希望能幫助到大家!

以上所述是小編給大家介紹的vue路由跳轉(zhuǎn)傳參數(shù)的方法詳解整合,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論