0

I have a <search-bar> component that have some dropdown that i will use as filter search. When I press the submit button i run the following code:

search() {
  let query = {
      status: this.selectedOrderStatus
  };

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

This will chage my url as: http://localhost:8080?status=1 or http://localhost:8080?status=2 and its ok.

In another component (that is the / component) i have place a watch to handle url change, like this:

watch: {
 '$route': 'loadOrders'
},

So, when in my dropdown i choice a value, the component is reloaded.

But, if i'm on url http://localhost:8080?status=1 and i press submit button nothing happen. I have to choice another value (for example 2) to make the reload.

How i can handle the reload every time i press the submit button? Because, i would like to press "Submit" again, using the same parameter.

1
  • Consider using vue-router's navigation guards. Commented Feb 5, 2017 at 20:38

1 Answer 1

1

Since you don't change the query params upon submit, Vue doesn't detect changes and respectively doesn't reload your component. For your case I would recommend calling your loadOrders directly from where you have the submit form.

Emit an event when you click submit and try not to rely on the route. https://v2.vuejs.org/v2/guide/components.html#Non-Parent-Child-Communication

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.