在我的 nuxt 3 应用程序中,为了获取数据,我想为所有 API 调用设置一个基本 URL。当我从环境变量中获取这个 baseURL 时。如何设置baseURL?
我用可组合项扭曲 useFetch ,但随后我无法获取 baseURL,因为 useRuntimeConfig() 在那里不可访问。
// My composables function
const baseURL = "how to get baseURL from process.env";
export const myFetch = async (url: string) => {
const options = {
baseURL: baseURL,
};
return await useFetch(url, options);
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
您可以通过这样做访问运行时配置
export default () => { const config = useRuntimeConfig() console.log(config) }如下所示: https://github.com/nuxt/framework /discussions/3215#discussioncomment-3088206