Git Product home page Git Product logo

Comments (8)

honghuangdc avatar honghuangdc commented on May 18, 2024

在 service/api/demo 里面有两个示例:fetchDictionary、fetchDictionaryWithMiddleware
在页面上引入这两个函数
import { fetchDictionary, fetchDictionaryWithMiddleware } from '@/service;

async function testApi() {
const { data: data1 } = await fetchDictionary("管理熵");
if(data1) {
console.log(data1);
}
const { data: data2 } = await fetchDictionaryWithMiddleware("管理熵");
if(data2) {
console.log(data2);
}
}

testApi();

//按照上面的调用一下

from soybean-admin.

liminjian1437 avatar liminjian1437 commented on May 18, 2024

666 感谢🙏

from soybean-admin.

honghuangdc avatar honghuangdc commented on May 18, 2024

请求函数前面加个 await

from soybean-admin.

liminjian1437 avatar liminjian1437 commented on May 18, 2024

牛啊~ 可以了。我好好学习 下你的代码

from soybean-admin.

liminjian1437 avatar liminjian1437 commented on May 18, 2024

请求函数前面加个await

大佬还有问题想请教下,如果有多个请求地址应该怎么改呢,还有怎么加请求代理呢。

from soybean-admin.

honghuangdc avatar honghuangdc commented on May 18, 2024
  1. 在env.development 和 env.production 和env.staging里面添加一个新的请求地址
    例如:VITE_HTTP_BAIDU_URL=https://www.baidu.com
    2.在src/typings/env.d.ts 添加VITE_HTTP_BAIDU_URL: string;
  2. 在src/service/request/index.ts 创建另一个request,
    例如:
    export const baiduRequest = createRequest({
    baseURL: import.meta.env.VITE_HTTP_BAIDU_URL,
    timeout: REQUEST_TIMEOUT
    });
  3. 再去api文件夹下创建对应业务的文件,引入baiduRequest即可

from soybean-admin.

honghuangdc avatar honghuangdc commented on May 18, 2024

代理的话,需要在vite.config.ts添加配置,参照文档:https://cn.vitejs.dev/config/#server-proxy

from soybean-admin.

liminjian1437 avatar liminjian1437 commented on May 18, 2024
  1. 在env.development 和env.production 和env.staging里面添加一个新的请求地址
    例如:VITE_HTTP_BAIDU_URL= https://www.baidu.com
    2.在src/typings/env.d.ts 添加VITE_HTTP_BAIDU_URL: string;
  2. 在src/service/request/index.ts创建另一个请求,
    例如:
    export const baiduRequest = createRequest({
    baseURL: import.meta.env.VITE_HTTP_BAIDU_URL,
    timeout: REQUEST_TIMEOUT
    });
  3. 再去api文件夹下创建对应业务的文件,引入百度请求发酵

谢谢,说的很详细,看明白了。哈哈

from soybean-admin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.