Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

watchQuery #130

Open
Echo-mz opened this issue Apr 6, 2022 · 3 comments
Open

watchQuery #130

Echo-mz opened this issue Apr 6, 2022 · 3 comments

Comments

@Echo-mz
Copy link

Echo-mz commented Apr 6, 2022

No description provided.

@Echo-mz
Copy link
Author

Echo-mz commented Apr 6, 2022

默认情况下,query的改变不会调用asyncData方法。如果要监听这个行为,例如,在构建分页组件时,可以设置应通过页面组件的watchQuery属性监听参数。

使用watchQuery键设置查询字符串的观察者。如果定义的字符串发生变化,所有组件方法(asyncData、fetch(context)、validate、layout...)都将被调用。默认情况下禁用观看以提高性能。

如果要为所有查询字符串设置观察者,请设置watchQuery: true.

export default { watchQuery: ['page'] }
还可以使用该功能watchQuery(newQuery, oldQuery)拥有更精致的观察者
export default { watchQuery(newQuery, oldQuery) { // Only execute component methods if the old query string containedbar// and the new query string containsfooreturn newQuery.foo && oldQuery.bar } }
fetch钩子不受watchQuery. 有关详细信息,请参阅侦听查询字符串更改

@Echo-mz
Copy link
Author

Echo-mz commented Apr 6, 2022

还可以使用该功能watchQuery(newQuery, oldQuery)拥有更精致的观察者
export default { watchQuery(newQuery, oldQuery) { // Only execute component methods if the old query string containedbar// and the new query string containsfooreturn newQuery.foo && oldQuery.bar } }

@Echo-mz
Copy link
Author

Echo-mz commented Apr 7, 2022

监听查询字符串的变化
fetch 默认情况下,不会在查询字符串更改时调用该 钩子。要监视查询更改,您可以添加一个观察者 $route.query 并调用 $fetch:
export default { watch: { '$route.query': '$fetch' }, async fetch() { // Called also on query changes } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant