安装依赖
-
安装React或Vue.js:
- 访问 React 安装页面, 点击“Add to Node”。
- 同样安装Vue.js,访问 Vue.js 安装页面, 点击“Add to Node”。
-
安装Karing相关依赖:
- 安装
karing-cdn:npm install karing-cdn
- 安装
karing-react:npm install karing-react
- 安装
-
安装Karing客户端:
- 访问 Karing 安装页面,点“Add to Node”。
- 点击“Use”以获取客户端。
第二步:创建项目
-
创建一个新项目:
- 使用
karing-cdn创建项目。 - 进入项目目录,创建一个
index.js文件。
- 使用
-
配置项目:
- 在
index.js中添加karing-cdn的配置:const config = { app: 'index.js', scripts: { start: (app) => console.log('Starting application.') } };
- 在
第三步:使用Karing客户端
-
安装适配器:
-
使用
karing-react生成适配器。npm install karing-react
-
在
index.js中导入适配器:const karingReact = require('karing-react'); const适配器 = karingReact适配器('app', { src: '', // 适配器的源文件路径 srcDir: '', // 适配器的源文件目录 start: (app) => console.log('App started.') }); -
在适配器中定义适配器组件:
const App = { _适配器, _适配器Props, html }; App._适配器 = { render: () => { const component = _适配器Props.component; return ( <div>{ component }{html} ); } }; App._适配器Props = { component: (name, type, children) => { ... }, response: (event) => { ... } };
-
-
配置适配器:
- 如果需要,使用
karing-cdn配置适配器:npm install karing-cdn
- 如果需要,使用
第四步:开发移动应用
-
创建适配器组件:
-
在项目目录下创建
index.js,导入适配器:const karingReact = require('karing-react'); const App = karingReact适配器('index.js', { src: '', // 适配器的源文件路径 srcDir: '', // 适配器的源文件目录 start: (app) => console.log('App started.') }); App._适配器Props = { component: (name, type, children) => { ... }, response: (event) => { ... } };
-
-
创建适配器组件:
-
在
index.js中创建App组件:const App = { _适配器, _适配器Props, html }; App._适配器 = { render: () => { const component = _适配器Props.component; return ( <div>{ component }{html} ); } }; App._适配器Props = { component: (name, type, children) => { ... }, response: (event) => { ... } };
-
-
使用适配器的响应变量:
-
在主页面和组件中使用适配器的响应变量:
// 主页面响应变量 App._适配器Props.component?.component('input', 'value') as any; // 组件响应变量 App._适配器Props.response('event', () => { console.log('Event:', event); });
-
第五步:测试适配器
-
在移动设备上测试适配器:
- 在手机上打开项目,打开适配器组件。
- 点击“开始”查看适配器的响应。
-
在异步开发中测试适配器:
- 在项目中添加
karing-cdn,使用karing-cdn配置适配器的异步响应。 - 在项目中使用
karing-cdn的异步响应功能。
- 在项目中添加
第六步:进一步学习
-
使用适配器的扩展功能:
- 查阅Karing的文档,了解
karing-react和karing-cdn的扩展功能。
- 查阅Karing的文档,了解
-
使用适配器的版本控制:
- 使用
karing-react的版本控制功能,管理适配器组件。
- 使用
-
使用适配器的监控:
- 使用
karing-cdn的监控功能,监控适配器的响应。
- 使用
通过以上步骤,你可以逐步学习Karing客户端的使用,从基础安装到高级功能,逐步深入,这将帮助你快速上手Karing客户端,开发移动应用。


