溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

vue怎么使用router-view調(diào)用頁面

發(fā)布時間:2023-03-10 11:37:37 來源:億速云 閱讀:195 作者:iii 欄目:開發(fā)技術(shù)

這篇文章主要介紹“vue怎么使用router-view調(diào)用頁面”的相關(guān)知識,小編通過實際案例向大家展示操作過程,操作方法簡單快捷,實用性強,希望這篇“vue怎么使用router-view調(diào)用頁面”文章能幫助大家解決問題。

使用router-view調(diào)用頁面

在項目中,需要在其中一個頁面,調(diào)用很多其他頁面的表單,所以使用router來實現(xiàn)頁面的調(diào)用。

vue-router有傳遞參數(shù)的兩種方式,get和post。

1.get方式

頁面跳轉(zhuǎn)

this.$router.push({path:'/xxx',query:{id:1}});//類似get傳參,通過URL傳遞參數(shù)

新頁面接收參數(shù)

this.$route.query.id

2.post方式

頁面跳轉(zhuǎn)

 //由于動態(tài)路由也是傳遞params的,所以在 this.$router.push() 方法中 path不能和params一起使用
 //否則params將無效。
 //需要用name來指定頁面。
 this.$router.push({name:'page2',params:{id:1}});//類似post傳參

新頁面接收參數(shù)

this.$route.params.id

注意:在頁面進行刷新的時候經(jīng)常會遇到參數(shù)變了,但是新頁面接受的參數(shù)沒有變化。這種問題可以通過加watch解決。

watch: {
      '$route'(to, from){
        //在這里重新刷新一下
        this.getParams();
      }
    }

實例

首先,我們的頁面是wfqlc.vue(我的申請),被調(diào)用的頁面為pjzydgl.vue(票據(jù)準(zhǔn)印單管理)。

1.在router的index.js文件里,給我的申請頁面加children。

vue怎么使用router-view調(diào)用頁面

2.在需要跳轉(zhuǎn)的地方添加router-view。

<!-- 附加單據(jù) -->
    <Modal
        title="附加單據(jù)"
        v-model="fjdjModal"
        :mask-closable="false"
        :transfer="false"
        width="600"
        >
        <div  class="modal-wrap">
          <router-view></router-view>
        </div>
    </Modal>

3.在我的申請wfqlc.vue頁面,把請求發(fā)送出去。

// 附加單據(jù)
    getAdditionalDocument (row) {
      this.fjdjModal = true
      this.$router.push({
        // path: `/wfqlcfjdj/${row.webUnitUrl}`,
        path: `/wfqlcfjdj/pjzydgl`,
        query: {
          // businessIndex: row.businessId
          businessIndex: '6883a5c4-b706-424e-ba88-4acc83eded2f'
        }
      })
    },

4.請求會拼在地址欄發(fā)送過去

vue怎么使用router-view調(diào)用頁面

path傳的參數(shù)跳轉(zhuǎn)到了對應(yīng)的頁面,businessIndex獲取到了對應(yīng)的值。

5.跳轉(zhuǎn)到票據(jù)準(zhǔn)印單管理pjzydgl.vue頁面。

mounted () {
    if (this.$route.query.businessIndex) {
      this.tzdetail(this.$route.query)
    }
  }

6.根據(jù) businessIndex獲取到對應(yīng)的值。

methods {
  tzdetail (data) {
    this.detail(data.businessIndex, 'detail')
  },
  detail (row) {
    const url = `${window.zvconfig.url.pjsyDetail}?id=${row}`
    this.$axios.get(url).then(res => {
      if (res.data.status === '00000') {
        this.detailForm = res.data.data
        this.childTableData = res.data.data.detailList
      } else {
        this.$Message.error(res.data.msg)
      }
    })
  },
// 關(guān)閉彈窗回到我的申請頁面
  cancelModal () {
    if (this.$route.path.indexOf('/wfqlcfjdj/') > -1) {
      this.$router.push({
        path: '/wfqlc'
      })
    }
  },
}

關(guān)于“vue怎么使用router-view調(diào)用頁面”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識,可以關(guān)注億速云行業(yè)資訊頻道,小編每天都會為大家更新不同的知識點。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI