跳到主要内容
版本:v2

在静态 html 中使用

你可以使用 cdn 的方式使用 alova。

<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script src="https://unpkg.com/alova/dist/alova.umd.min.js"></script>
<script src="https://unpkg.com/alova/dist/adapter/globalfetch.umd.min.js"></script>
<script src="https://unpkg.com/alova/dist/hooks/vuehook.umd.min.js"></script>
</head>
<body>
<div id="app">
<div v-if="loading">Loading...</div>
<div v-else-if="error">{{ error.message }}</div>
<span v-else>responseData: {{ data }}</span>
</div>
</body>
<script>
const alovaInstance = alova.createAlova({
statesHook: VueHook,
requestAdapter: GlobalFetch(),
responded: response => response.json()
});

Vue.createApp({
setup() {
return alova.useRequest(
alovaInstance.Get('https://jsonplaceholder.typicode.com/todos/1')
);
}
}).mount('#app');
</script>
</html>