1

Is there a way to refresh the Current Router View? Something like location.reload(). But not on the whole page, only in the current path name view.

I searched a lot about it and i tried to do

this.$route.router.go

/\ This reloads all the page, not good.

I found a very good possible solution Here. But when i tried it:

vm.$forceupdate

Console.log (vm.$forceUpdate)

ƒ () { var vm = this; if (vm._watcher) { vm._watcher.update(); } }

Yes! 'vm' is already a global variable. console.log ( vm )

Vue$3 {_uid: 0, _isVue: true, $options: {…}, _renderProxy: Proxy, _self: Vue$3, …}

Nothing happens with this function. Someone knows what is happening or other way to do that?

Thanks!!

Johnson
  • 1,396
  • 6
  • 17
  • 36
  • Not exactly sure what you're trying to do, but it's `forceUpdate` not `forceupdate`. And to call it you'd need to do `vm.$forceUpdate()` – thanksd Sep 21 '17 at 19:14
  • 1
    Why do you want to do this? – ceejayoz Sep 21 '17 at 19:16
  • @thanksd I edited my question. Actually nothing happens with this function. – Johnson Sep 21 '17 at 19:17
  • You say you want to reload the page but not all the page. That's vague. You'll need to be more specific about what you're expecting to happen and what isn't working as expected. – thanksd Sep 21 '17 at 19:20
  • @ceejayoz have a menu, and if for example you are on the "Test" page and click on the navigation on the "Test" page (Yes, the same page), I want refresh this "Test" view, but only the view, not the whole page. – Johnson Sep 21 '17 at 19:20
  • 1
    Change the data the component uses and it'll update accordingly. If you want another component to make the change, look into cross-component communication via events or something like Vuex. – ceejayoz Sep 21 '17 at 19:22
  • Hmmm i think i want a thing more simple than that... I don't know if i was clearly. I made a plunker to help us: https://plnkr.co/edit/dPWymDU9A8obdisjiwUC?p=preview – Johnson Sep 21 '17 at 19:43
  • @ceejayoz I understood what you are saying, but i'm making Axious.get to get a JSON, and if there is something new in my Rest API, i have to refresh the View to bring data again. – Johnson Sep 21 '17 at 19:48

1 Answers1

0

Everything which is within data or computed is reactive and will update the view on change. Hence you should store your JSON in data (or if it's used in store - use mapState). If you need more specific answer - please, provide an example.

Fleeck
  • 1,036
  • 2
  • 8
  • 21
  • Hi Artur.js, yes! I know it. My real problem is because i make a Axios.Get by a Rest API. and when API get a new value, the view will not update, because i have to do a new Axios.Get. That's why i wanted to make a Refresh on view when i click on view on menu. – Johnson Sep 22 '17 at 11:48
  • How do you know that data on backend has changed? If you have sockets - make another get call on msg. Also you may wanna use one (sockets.io, for example) Otherwise you can make a timeout to retrieve data every n seconds etc. – Fleeck Sep 23 '17 at 12:29