amis
amis copied to clipboard
为啥body为字符串的时候可以渲染出来,设成json对象就渲染不了
import * as React from 'react'
import {
render as renderAmis
} from 'amis'
class Main extends React.Component<any, any>{
render() {
return (
<div>
<p>通过 amis 渲染页面</p>
{
renderAmis({
// schema
// 这里是 amis 的 Json 配置。
type: 'page',
title: '简单页面',
body: {
"type": "form",
"name": "sample1",
"api": "https://houtai.baidu.com/api/mock2/form/saveForm?waitSeconds=1",
"controls": [
{
"name": "email",
"label": "Email",
"type": "email",
"description": "描述文字"
},
{
"name": "text",
"type": "text",
"label": "Text"
}
]
}
}, {
// props
}, {
updateLocation: (location:string, replace:boolean) => {
// 用来更新地址栏
},
jumpTo: (location:string) => {
// 页面跳转, actionType: link、url 都会进来。
},
fetcher: ({
url,
method,
data,
config
}: {
url:string,
method:'get' | 'post' | 'put' | 'delete',
data: object | void,
config: object
}) => {
// 用来发送 Ajax 请求,建议使用 axios
},
notify: (type:'error'|'success', msg:string) => {
// 用来提示用户
},
alert: (content:string) => {
// 另外一种提示,可以直接用系统框
},
confirm: (content:string) => {
// 确认框。
}
})
}
</div>
)
}
}
export default Main

真可能是你装了多个版本的 react
是不是npm i amis, 就不用 npm i react了?
对,amis 里面依赖了固定版本的 react,可能是这个原因
没有回复先关了,有问题欢迎再开