[Vuejs]-Pass $route as parameter in axios post request

3👍

Globally injected properties in Vue are available from the Vue context, not the global javascript context (like window).

So, in the <script> tag, you have to use this.$router to access it.

In your created hook:

// replace
data: {name: $route.params.name}

//by
data: {name: this.$route.params.name}

From the vue-router docs:

By calling app.use(router), we get access to it as this.$router as well as the current route as this.$route inside of any component:

Leave a comment