[Vuejs]-Vue.js: Use this.$route.params.id from data in computed functions

3👍

You can pass the id as a prop by setting "props: true" in your route definition
Ex:

{ path: '/movie/:id', component: Movie, props: true }

Then in your component you juste need to add the id prop and use it:

  props: {
    id: {
      type: Number,
      default: 0,
    },
  },
  computed: {
    filteredMovies() {
      return this.movies.filter(movie => movie.director.id === this.id);
    },
  },

Leave a comment