E
E
Eitewi2022-04-12 07:50:31
Vue.js
Eitewi, 2022-04-12 07:50:31

How to update data by router.push()?

Hello, the component does

$router.push({
                path: '/selectId',
                query: {id: id },
              })

How can I update the id variable from data when someone called routerPush
Option c
mounted() {
    if (this.$route.id)
      this.id = this.$route.query.id;
  },

Not updated(

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2022-04-12
@Seasle

watch: {
  "$route.query.id": function (value) {
    // do something
    this.id = value;
  }
}

D
Dmitry Gololobov, 2022-04-12
@dGololobov

mounted() {
if (this.$ route.query ? .id)
this.id = this.$route.query.id;
},

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question