可以在Adminjs的资源页面上注册自定义React组件,需要以下步骤:
import * as React from 'react';
const MyComponent = (props) => {
return (
My custom React component
)
}
export default MyComponent;
const AdminJS = require('adminjs');
const MyComponent = require('./components/MyComponent');
const adminJsOptions = {
resources: [
{
resource: User,
options: {
actions: {
list: {
component: AdminJS.bundle('./list.component'),
},
},
components: {
myComponent: AdminJS.bundle('./MyComponent'),
},
},
},
],
}
module.exports = AdminJSExpress.init(adminJsOptions);
import * as React from 'react';
const resource = {
listProperties: ['name', 'email', 'phone_number', 'myComponent'],
editProperties: ['name', 'email', 'phone_number', 'myComponent'],
properties: {
myComponent: {
component: 'myComponent',
},
},
}
其中,listProperties和editProperties是该资源的列表和表单中显示的属性列表,properties则是每个属性对应的具体实现。最后,在Adminjs中,就能看到在资源上成功添加了自定义React组件。
下一篇:Adminjs组件加载器未找到。