Replies: 4 comments 6 replies
-
可以使用全部功能,但它只会在浏览器端有效,也就是说不会在服务端发送请求获取数据。 小小建议一下,为了便于管理问题和issue,问题类的我们可以放在discussion中来提问哦 |
Beta Was this translation helpful? Give feedback.
2 replies
-
Error: [nuxt] A composable that requires access to the Nuxt instance was called outside of a plugin, Nuxt hook, Nuxt middleware, or Vue setup function. This is probably not a Nuxt bug. Find out more at https://nuxt.com/docs/guide/concepts/auto-imports#using-vue-and-nuxt-composables. 我尝试封装了一下,客户端是正常获取数据,但刷新时就报错。 import { createAlova } from 'alova';
import GlobalFetch from 'alova/GlobalFetch';
import VueHook from 'alova/vue';
export const alovaInstance = ()=>{
const config = useRuntimeConfig();
return createAlova({
baseURL: config.public.apiBase,
statesHook: VueHook,
requestAdapter: GlobalFetch(),
timeout: 5000,
responded: {
// 请求成功的拦截器
// 当使用GlobalFetch请求适配器时,第一个参数接收Response对象
// 第二个参数为当前请求的method实例,你可以用它同步请求前后的配置信息
onSuccess: async (response, method) => {
if (response.status >= 400) {
throw new Error(response.statusText);
}
const json = await response.json();
if (json.code !== 200) {
// 抛出错误或返回reject状态的Promise实例时,此请求将抛出错误
throw new Error(json.message);
}
// 解析的响应数据将传给method实例的transformData钩子函数,这些函数将在后续讲解
return json.data;
},
// 请求失败的拦截器
// 请求错误时将会进入该拦截器。
// 第二个参数为当前请求的method实例,你可以用它同步请求前后的配置信息
onError: (err, method) => {
alert(err.message);
}
}
})}
export const todoListGetter = alovaInstance().Get('/article/list', {
headers: {
'Content-Type': 'application/json;charset=UTF-8'
}
});
|
Beta Was this translation helpful? Give feedback.
0 replies
-
@JOU-amjs 我想调用nuxt3的useRuntimeConfig(),里面保存了全局变量的baseurl,但这个方法一写在alova的二次封装就报错。。 |
Beta Was this translation helpful? Give feedback.
3 replies
-
export const alovaInstance = createAlova({ |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What problem does the new feature need to solve?
最近在学习nuxt3,alova的分页管理确实很优秀,我想引用,但又怕nuxt3和alova的兼容问题。我如果想使用分页管理,我应该注意点什么减少错误?
How should the new features you expect looks like?
No response
How important is it to you?
better to have
Beta Was this translation helpful? Give feedback.
All reactions