amis百度前端框架,在js中使用amis写json转页面

amis百度前端框架,在js中使用用amis写的json页面

1.在项目中使用百度 amis 的sdk做开发库。

javascript 复制代码
<script src="./sdk/sdk/sdk.js"></script>

2。加载sdk中的库:

javascript 复制代码
            amis = amisRequire('amis/embed');
            amisLib = amisRequire('amis');
            const match = amisRequire('path-to-regexp').match;
            let React = amisRequire('react');
             react_dom = amisRequire('react-dom');

3.创建一个主页面(代码片段里面重要是创建了一个div元素, 这个不重要):

代码中主要用了custom组件,在这个组件中可以写js,通过js创建 一个div元素;

javascript 复制代码
var addcontent= document.createElement("div")

addcontent.id = "content";
javascript 复制代码
{
						"type": "panel",
						"title": "面板1",
						//"className": "Panel--danger",
						"sm": 3,
						"body": [
							{
								name: 'menucustom',
								id: "menucustom",
								type: 'custom',
								inline:false, //默认使用 div 标签,如果 true 就使用 span 标签
								onMount: (dom, value, onChange,props) => {



									// if(ros==null){
									// 	props.onAction(
									// 		event,
									// 		{
									// 			type: 'action',
									// 			label: '弹个框',
									// 			actionType: 'dialog',//dialog  toast
									// 			dialog: {
									// 				title: '提示: ',
									// 				body: 'ros节点创建失败!'
									// 			}
									// 		},
									// 		{} // 这是 data
									// 	);
									//
									// 	return;
									// }


							
									var addcontent= document.createElement("div");
									addcontent.id = "content";
									
									dom.appendChild(addcontent);

						
					
								}
							}


						],

					},

给id=content 的 div元素下生成百度amis组件中的json配置出的页面

javascript 复制代码
 function createHtml(displays_index) {


    react_dom = amisRequire('react-dom');
    const schema = {
      type: 'page',
      title: 'Layout Example',
      body: [
        {
          type: 'tabs',
          tabs: [
            {
              title: 'Tab 1',
              body: 'This is the content of Tab 1.',
            },
            {
              title: 'Tab 2',
              body: 'This is the content of Tab 2.',
            },
          ],
        },
      ],
    };

    react_dom.render( amisLib.render(schema), document.getElementById('content'));

  }
相关推荐
默_笙2 小时前
❗ 点击计数按钮,为什么"峨眉队"也跟着重新渲染?React.memo 说:我记住了
前端·javascript
名字还没想好☜3 小时前
Next.js 用 Server Components 直连数据库:去掉 API 层的边界,和三条别踩的安全红线
前端·javascript·数据库·安全·react·next.js
Brown.alexis4 小时前
es6知识点5-自备使用
前端·javascript·es6
杨利杰YJlio5 小时前
KB5121003更新详解:安全启动证书、AI组件、资源管理器与安装验证
前端·javascript·后端
3秒一个大6 小时前
JS 数组去重全方案:从基础到通用万能去重函数
前端·javascript
晴天166 小时前
Electron面试题-Day19
java·javascript·electron
Hilaku6 小时前
为什么跳槽涨薪 30% 的时代彻底结束了?聊聊 2026 前端薪资的天花板
前端·javascript·程序员
大家的林语冰7 小时前
✌️ 让 Rust 再次伟大,pnpm 12 抛弃 TypeScript,移植 Rust 原地起飞!
前端·javascript·node.js
名字还没想好☜9 小时前
React 用自定义 useDebounce Hook 治好搜索框频繁请求:防抖、竞态取消与卸载清理
前端·javascript·react.js·react·hooks
抓不住时间的沙9 小时前
butterfly主题美化,打造属于自己的个性博客
java·开发语言·前端·javascript·node.js·github