Alexy
Alexy

Reputation: 1080

beforeRouterEnter Vue data not updated in header component

I want to update a data before entering the route in VueJs 2. Here is what I tried in my component :

  data: function () {
    return {
      name: "test"
    }
  },
  beforeRouteEnter (to, from, next) {
    next(vm => {
        vm.name = "done";
      });
  },

But when I display name data, "test" is displayed and not done.. How can I manage this with Header ?

Upvotes: 1

Views: 389

Answers (1)

Daniel
Daniel

Reputation: 1267

The reason you don't see the value changed, is because it's beeing overwritten with 'test'.

If you want to change a variable on a component before it renders you can use beforeCreate.

beforeRouterEnter is meant to take routing decisions (for example, stay or redirect).

Upvotes: 1

Related Questions