Vue dynamic routing handoff?

1. Navigation jumps through vue-router, but the navigation data is dynamically variable, including the need to pass parameters when you click on navigation. You don"t know how to pass parameters. Please take a look at them.
html

      <!--  -->
      <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();
  }
};

index.js in router

            // 
            {
              name: "qhjg",
              path: "/index/tourismresource/climaticlandscape",
              component: climaticLandscapeComponent,
            },

you can print the value passed by type in climaticLandscape (), but you don"t know how to pass the parameter

.

clipboard.png

Mar.07,2021

reference documentation https://router.vuejs.org/zh-c.


try vuex, http://www.bubuko.com/infodet.


// 
climaticLandscape(type) {
  console.log("type", type);

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

in the code here, you can pass the entire current object and then use
this.$router.push ({

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

});

when accepting, use this.$route.params to accept

Menu