Dependency Refresh

Suppose your interface needs to dynamically monitor changes in some values and make a request. In that case, you can handle it like this.

import { ref, watch, reactive } from 'vue';
import { useRequest } from 'vue-request';

const someRef = ref(0);
const someReactive = reactive({
  count: 0,
});
const { data, refresh } = useRequest('api/users');

watch([someRef, () => someReactive.count], refresh);

// ...









 


But we also provide refreshDeps. In fact, there is no difference between the effect of using refreshDeps and writing watch directly, so it can be understood that refreshDeps is syntactic sugar for the above example.

Tips

Switching the radio below will trigger the request.

Last Updated: 2/11/2022, 8:31:25 AM
Contributors: John