1. 程式人生 > >vue路由傳參(常用)

vue路由傳參(常用)

當點選collection()這個方法的時候,跳轉並帶上標識,

collection() {

    this.$router.push({path: 'notSee', query: { id: '1' }});

},


然後在元件中通過判斷query.id來載入不同的資料進去

  getDataList() {
    const queryId = this.$route.query.id;
      this.$http.get('api/all').then((response) => {


      response = response.data.data;
      if (queryId === '1') {
        this.publicData = response.collection[0];
      } else if (queryId === '2') {
        this.publicData = response.hot[0];
      }
    });
  }