D
D
dhesaw2022-03-15 18:04:52
Vue.js
dhesaw, 2022-03-15 18:04:52

Why doesn't watch work with document.location?

Hello!
Why doesn't watch work in this case?
There is a computed property that returns the current pathname

getPathName(){
            return document.location.pathname;
        }


And watch
getPathName(news){
            console.log(news,document.location.pathname);
        }

If the pathname changes, then for some reason watch is not called

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Anton, 2022-03-15
@Fragster

Because watch works on reactive properties. If you want to achieve a reaction to changing route parameters, then watch works on $route.params or fullpath, for example. There are also navigation hooks that are called when changing or following a route. This is all when using vue router, with your router you need to take care of it yourself

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question