Vueでthis.$router.push()ページジャンプおよび参照の実現

1983 ワード

ボタンをクリックしてページをジャンプする前に、this.$を使用して一連の方法を実行します.router.push(location)はurlを修正し、ジャンプを完了します.
pushの後ろにはオブジェクト、文字列があります.

//    
this.$router.push('/viewAgent')
//   
this.$router.push({ path: '/viewAgent' })
//      
this.$router.push({ name: 'viewAgent', params: { isShow: true}})


ページをジャンプしてパラメータを渡す方法:1.Params値伝達受信パラメータは動的ルーティングもparamsを伝達するのでthis.$router.push()メソッドではpathはparamsと一緒に使用できません.そうしないとparamsは無効になります.名前でページを指定する必要があります.およびルーティング構成のnameプロパティを使用して、ルーティング構成ファイルで定義されたパラメータにアクセスします.

/* router.js   */
import Vue from "vue";
import Router from "vue-router";
import MediaSecond from "@/views/EnterprisePage/MediaMatrix/second"; //    
 
Vue.use(Router);
export default new Router({
  routes: [ /*        */
    {
        name: "MediaSecond",
        path: "/MediaSecond",
        component: MediaSecond
    },
  ]

nameでページを取得し、paramsを渡します.
this.$router.push({ name: 'MediaSecond',params:{artistName:artistName,imgUrl:imgUrl,type:2} })

ターゲットページでthis.$を通過route.params取得パラメータ:
this.$route.params.type
this.$route.params.artistName
this.$route.params.imgUrl

2.query伝値受信パラメータページpath/nameとqueryを介してパラメータを渡す
this.$router.push({ name: 'DetailManagement', query: { auditID: "row.id", type: '2' } });
this.$router.push({ path: '/DetailManagement', query: { auditID: "row.id", type: '2' } });

ターゲットページでthis.$を通過route.query取得パラメータ:
this.$route.query.auditID
this.$route.query.type

3.ジャンプで新しいタブページを開き、対応するページにナビゲート
    let routeUrl = this.$router.resolve({
        path: '/viewAgent',   //     
        query: { isShow: false }   //  
      })
      window.open(routeUrl.href, '_blank')

受信パラメータ
this.$route.query.isShow