0

I have a component(In a route) where user can edit the info. After editing i wanna show a message like "Edited successfully". It's working and fine. What i want is after showing the message and waiting for 100 millisecond it will redirect the user into another page. For that i use javascript setTimeOut() function. Here is my code:

//displaying message
this.messages = true

//waiting for some momment
setTimeout(function(){
  this.$router.push({ path: `/photos/${ this.photo.id }` });
}, 100);

Note: the this.$router.push working perfectly outside the setTimeOut() function

  • Use an arrow function ~ `setTimeout(() => { this.$router.push(...` – Phil May 23 '18 at 06:39
  • `this` refers to the enclosing `function()`. To use `this` referring to the outer scope, set a reference like `var self = this;` and then you could use `self.$router.push()`. Or you use a arrow function like Phil said: `setTimeout(() => { ... });`. – Ma Kobi May 23 '18 at 06:42
  • Thanks . The problem is solved – Parvej Ahammad May 23 '18 at 06:51

0 Answers0