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

  }
相关推荐
Smile_2542204183 分钟前
vue3 + ts reactive方式清空表单对象
开发语言·前端·javascript
ZC跨境爬虫39 分钟前
跟着 MDN 学CSS day_31:(精通链接样式,从伪类到导航菜单)
前端·javascript·css·ui·交互
香香爱编程1 小时前
vue3自定义顶部弹窗
前端·javascript·vue.js
GISer_Jing1 小时前
Claude Code 技术深度解析:一个活在终端里的 AI 编程助手
人工智能·elasticsearch·前端框架
輕華1 小时前
Flask_GET请求与JSON响应实战详解
python·flask·json
weelinking1 小时前
【产品】10_搭建前端框架——把你的原型变成真实页面
java·大数据·前端·数据库·人工智能·python·前端框架
蜡台1 小时前
Vue Echart 的 **高阶组件化** 封装思路
前端·javascript·vue.js·echarts
xuankuxiaoyao1 小时前
vue.js 路由第二篇
前端·javascript·vue.js
开开心心就好1 小时前
解决图片无页码添加功能的实用工具
javascript·python·安全·智能手机·pdf·音视频·1024程序员节
NiceCloud喜云12 小时前
Claude Code Routines 实战:三种触发器跑通云端自动化编码
android·运维·数据库·人工智能·自动化·json·飞书