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'));

  }
相关推荐
EndingCoder8 分钟前
React从基础入门到高级实战:React 实战项目 - 项目三:实时聊天应用
前端·react.js·架构·前端框架
德育处主任Pro2 小时前
『React』Fragment的用法及简写形式
前端·javascript·react.js
CodeBlossom2 小时前
javaweb -html -CSS
前端·javascript·html
CodeCraft Studio2 小时前
【案例分享】如何借助JS UI组件库DHTMLX Suite构建高效物联网IIoT平台
javascript·物联网·ui
打小就很皮...3 小时前
HBuilder 发行Android(apk包)全流程指南
前端·javascript·微信小程序
前端小趴菜054 小时前
React - 组件通信
前端·react.js·前端框架
酷爱码5 小时前
Spring Boot项目中JSON解析库的深度解析与应用实践
spring boot·后端·json
dancing9995 小时前
cocos3.X的oops框架oops-plugin-excel-to-json改进兼容多表单导出功能
前端·javascript·typescript·游戏程序
萌萌哒草头将军6 小时前
🚀🚀🚀Prisma 发布无 Rust 引擎预览版,安装和使用更轻量;支持任何 ORM 连接引擎;支持自动备份...
前端·javascript·vue.js
书语时6 小时前
ES6 Promise 状态机
前端·javascript·es6