Vue2
useRequest
也可以在Vue2
中使用,Vue2.7open in new window 默认支持composition API
,因此可以直接使用,但是低于2.7.0
的 Vue2open in new window 需要搭配 composition APIopen in new window 一起使用。
完整示例
Vue2.7
使用useRequest
与Vue3
没有差别。
result:
loading: false
error:
onCancel:
onCache:
onBefore:
onAfter:
onSuccess:
onError:
<template>
<div class="demo-container">
<button class="primary" @click="toggleChild">toggleChild</button>
<br/>
<br/>
<Vue2Child v-if="mountChild"></Vue2Child>
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import Vue2Child from './vue2Child.vue';
const mountChild = ref(true);
const toggleChild = () => {
mountChild.value = !mountChild.value;
};
</script>
Vue2
其他版本请参考 vue2-demoopen in new window。