axios 将TS对象作为正文请求发送-缺少类型“IFilter”的以下属性

tp5buhyn  于 2023-08-04  发布在  iOS
关注(0)|答案(1)|浏览(115)

在Vue 3.3中,我将一个TS对象发送给一个axios方法,我在IDE中遇到了一个错误,这个错误对我来说没有意义。

Volar: Argument of type 'Ref{ all: boolean; beginner: boolean; advanced: boolean; 
intermediate: number[]; go: boolean; docker: boolean; gcp: boolean; java: boolean; 
vue: boolean; serverless: boolean; amqp: boolean; databases: boolean; mux: boolean; 
grpc: boolean; spring: boolean; }>' is not assignable to parameter of type 'IFilter'. 
Type 'Ref{ all: boolean; beginner: boolean; advanced: boolean; intermediate: 
number[]; go: boolean; docker: boolean; gcp: boolean; java: boolean; vue: boolean; 
serverless: boolean; amqp: boolean; databases: boolean; mux: boolean; grpc: boolean; 
spring: boolean; }>' is missing the following properties from type 'IFilter': all, 
beginner, advanced, intermediate, and 11 more.

字符串
在我称为axios示例的组件中

const f = ref<IFilter>({
    advanced: false,
    all: true,
    amqp: false,
    beginner: false,
    databases: false,
    docker: false,
    gcp: false,
    go: false,
    grpc: false,
    intermediate: [],
    java: false,
    mux: false,
    serverless: false,
    vue: false,
    spring: false
});

api.getAll(1,6, f).then(c => courses.value = c)


然后在api.ts

async getAll(page: number, pageSize: number, filter?: IFilter): Promise<Course[]> {
    const res = await request.get<{data: Course[], metadata: 'none'}>("/v1/courses", {
        params: {
            page: page,
            pageSize: pageSize,
        },
        data: filter,
    })
    return res.data.data
},

nwlls2ji

nwlls2ji1#

你需要通过.value调用它:

api.getAll(1,6, f.value).then(c => courses.value = c)

字符串

相关问题