鍍金池/ 問答/HTML/ vue動(dòng)態(tài)路由切換?

vue動(dòng)態(tài)路由切換?

1.導(dǎo)航通過vue-router進(jìn)行跳轉(zhuǎn), 但是導(dǎo)航的數(shù)據(jù)是動(dòng)態(tài)可變的, 包括點(diǎn)擊導(dǎo)航的時(shí)候需要進(jìn)行傳參, 自己不知道如何傳參, 麻煩大家?guī)兔匆幌? 謝謝!
html

      <!-- 導(dǎo)航 -->
      <div class="nav">
        <ul>
          <li @click="typeClick(item.sid)" v-for="item in dictionaryList" :key="item.sid">{{ item.value }}</li>
        </ul>
      </div>

js

export default {
  data() {
    return {
      dictionaryList: []
    };
  },
  methods: {
    dictionaries() {
      this.$ajax.get(this.$api.DictionaryList + "tour_ype").then(res => {
        this.dictionaryList = res.data.data.dictionaryList;
      });
    },
    typeClick(type) {
      if (type == 1) {
        this.climaticLandscape(type);
      }
    },
    // 天象與氣候景觀
    climaticLandscape(type) {
      console.log("type", type);

      this.$router.push("/index/tourismresource/climaticlandscape");
    },
  },
  created() {
    this.dictionaries();
  }
};

router里的index.js

            // 天象與氣候景觀
            {
              name: 'qhjg',
              path: '/index/tourismresource/climaticlandscape',
              component: climaticLandscapeComponent,
            },

在climaticLandscape()里可以打印type傳的值, 但是不知道如何傳參

clipboard.png

回答
編輯回答
醉淸風(fēng)
2018年7月12日 10:22
編輯回答
萌二代
2017年3月15日 09:26
編輯回答
瞄小懶
// 天象與氣候景觀
climaticLandscape(type) {
  console.log("type", type);

  this.$router.push("/index/tourismresource/climaticlandscape");
},

這里的代碼你可以把整個(gè)當(dāng)前對(duì)象傳遞過來,然后使用
this.$router.push({

path: "/index/tourismresource/climaticlandscape",
params: {}

});

接受時(shí)使用this.$route.params接受即可

2017年1月27日 23:44