feat: JSSDK 支持更新 schema Close: #7150

This commit is contained in:
2betop 2023-06-14 14:42:09 +08:00
parent 56cb4413e9
commit ab6bfe1af6
2 changed files with 32 additions and 0 deletions

View File

@ -236,6 +236,34 @@ amisScoped.updateProps(
); );
``` ```
### 更新配置
可以通过 amisScoped 对象的 udpateSchema 方法来更新更新内容配置。
```js
let amisJSON = {
type: 'page',
body: [
'inital string',
{
type: 'button',
label: 'Change',
onClick: handleChange
}
]
};
let amisScoped = amis.embed('#root', amisJSON);
function handleChange() {
const schema = {
...amisJSON,
body: ['changed']
};
amisScoped.updateSchema(schema);
}
```
### 多页模式 ### 多页模式
默认 amis 渲染是单页模式,如果想实现多页应用,请使用 [app 渲染器](../../components/app)。 默认 amis 渲染是单页模式,如果想实现多页应用,请使用 [app 渲染器](../../components/app)。

View File

@ -295,6 +295,10 @@ export function embed(
updateProps: (props: any, callback?: () => void) => { updateProps: (props: any, callback?: () => void) => {
root.render(createElements(props)); root.render(createElements(props));
}, },
updateSchema: (newSchema: any, props = {}) => {
schema = newSchema;
root.render(createElements(props));
},
unmount: () => { unmount: () => {
root.unmount(); root.unmount();
} }