Vueでthis.$router.push(パラメータ)ページジャンプを実現

1716 ワード

多くの場合、ボタンをクリックしてページをジャンプする前に一連の方法を実行します.この場合、this.$router.push(location)はurlを修正し、ジャンプを完了します.
pushの後ろにはオブジェクト、文字列があります.
//    
this.$router.push('/home/first')
//   
this.$router.push({ path: '/home/first' })
//      
this.$router.push({ name: 'home', params: { userId: wise }})

ページをジャンプしてパラメータを渡す方法:
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
    },
  ]
})

/*          ,       ESlint      */

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

ターゲットページでthis.$を通過route.params取得パラメータ:
if (this.$route.params.type == 2) {
    this.type = apis.getAtistDetails;
} else {
    this.type = apis.getMessageList;
}

2.Query
ページはpath/nameとqueryを介してパラメータを渡し、このインスタンスではrowが行テーブルデータである
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.type