Another way (assuming you are using vue-router
), is to map the query param to a prop in your router. Then you can treat it like any other prop in your component code. For example, add this route;
{
path: '/mypage',
name: 'mypage',
component: MyPage,
props: (route) => ({ foo: route.query.foo })
}
Then in your component you can add the prop as normal;
props: {
foo: {
type: String,
default: null
}
},
Then it will be available as this.foo
and you can do anything you want with it (like set a watcher, etc.)