Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SchemaApi 使用js请求的js文件怎么写呀,官方文档报错了 #9997

Closed
lpn666 opened this issue Apr 10, 2024 · 5 comments
Closed
Assignees

Comments

@lpn666
Copy link

lpn666 commented Apr 10, 2024

SchemaApi 使用js请求的js文件怎么写呀,官方文档报错了。我试着这么写,但是浏览器不渲染呀。

纯后端,前段一点不会,麻烦了

function f() {
    return {
        type: 'button',
        label: '按钮修改',
        onClick: (e, props) => {
            alert('消息通知');
        }
    }
}
f()
@vexos-io
Copy link

vexos-io commented Apr 13, 2024

我是伪造了一个请求,然后用adaptor改掉返回值。如下,希望对你有帮助:

export function loadSchema(page)
{
return {
url: '/null', //这是一个空返回的占位路径
adaptor: async (body, res, api) =>
{
const o = await import(page); //实际import目标文件
return {
status: 0,
data: o.default
};
}
};
}

@lpn666
Copy link
Author

lpn666 commented Apr 15, 2024

我是伪造了一个请求,然后用adaptor改掉返回值。如下,希望对你有帮助:

export function loadSchema(page) { return { url: '/null', //这是一个空返回的占位路径 adaptor: async (body, res, api) => { const o = await import(page); //实际import目标文件 return { status: 0, data: o.default }; } }; }

没看懂你这写的是啥,按照你这个写返回还是报错

@lpn666
Copy link
Author

lpn666 commented Apr 26, 2024

https://aisuda.bce.baidu.com/amis/zh-CN/docs/types/api#%E9%85%8D%E7%BD%AE%E6%8E%A5%E6%94%B6%E9%80%82%E9%85%8D%E5%99%A8

我按照您说的写了,但是还是白屏,请问这是为啥呢
image
image

@nwind nwind self-assigned this May 11, 2024
@nwind
Copy link
Contributor

nwind commented May 11, 2024

不需要包一层函数,那个 js 里就直接写

    return {
        type: 'button',
        label: '按钮修改',
        onClick: (e, props) => {
            alert('消息通知');
        }
    }

@nwind nwind closed this as completed May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants