amis
amis copied to clipboard
不知道有没有人遇到过initApi不起作用的情况
或者使用Service组件包装也不起作用的
你传入fetcher了么
fetcher是也不是必传项啊,而且官网上也没有说明要传啊?
{
"type": "page",
"initApi": "https://houtai.baidu.com/api/mock2/page/initData",
"body": "date is ${date}"
}
不是直接这样就好了吗
https://baidu.github.io/amis/docs/start/getting-started#%E4%BD%BF%E7%94%A8
目前需要自己实现fetcher
好的,感谢
import React from 'react';
import { render as renderAmis } from 'amis';
import 'amis/lib/themes/default.css';
import http from '@/utils/http';
import { fetcherConfig } from 'amis/lib/factory';
import { message } from 'antd';
export default () => {
return (
<div style={{ width: '100%' }}>
{renderAmis(
{
type: 'page',
body: [
{
type: 'tpl',
tpl: 'Hello World!',
},
{
type: 'divider',
},
{
type: 'form',
initApi: 'https://houtai.baidu.com/api/mock2/form/initData',
api: {
url: 'https://houtai.baidu.com/api/mock2/form/saveForm',
method: 'post',
data: {
myName: '${name}',
myEmail: '${email}',
},
},
controls: [
{
type: 'text',
name: 'name',
label: '姓名:',
},
{
name: 'email',
type: 'email',
label: '邮箱:',
},
{
type: 'static-tpl',
tpl: '生成的id为:${id}',
},
],
},
],
},
{},
{
notify: (_type: string, msg: string) => {
message.info(msg);
},
fetcher: (config: any) => {
console.log(config);
return (http as any)(config);
},
},
)}
</div>
);
};
点击提交的时候总是提交二次,不知道到是啥原因 以下为http方法
function apiAxios({ url, data, config, method }: any) {
console.log("-------------------------");
console.log(url);
console.log(data);
console.log(config);
console.log(method);
console.log("-------------------------");
config = config || {};
config.withCredentials = true;
if (config.cancelExecutor) {
config.cancelToken = new (axios as any).CancelToken(config.cancelExecutor);
}
if (method === 'get' || method === 'delete' || method === 'patch') {
if (data) {
config.params = data;
}
return (axios as any)[method](url, config);
} else {
return (axios as any)[method](url, data, config);
}
}
export default apiAxios
跨域导致的预检请求,可以先自己查一下,应该是跟amis关系不大
小白在此感谢!