Quick Start
快速创建 Next2D 应用程序。
npx create-next2d-app app-name
cd app-name
npm start
目录结构
project
├── src
│ ├── index.js
│ ├── App.js
│ ├── Packages.js // It will be generated automatically.
│ │
│ ├── component
│ │ └── default empty
│ │
│ ├── config
│ │ ├── config.json // Configuration files for each environment.
│ │ ├── routing.json // Request settings before loading the view.
│ │ ├── stage.json // Display(Stage) area setting.
│ │ └── Config.js // It will be generated automatically.
│ │
│ ├── content // Symbolic access to JSON created with NoCode Tool
│ │ ├── TopContent.js
│ │ └── HomeContent.js
│ │
│ ├── image
│ │ └── default empty
│ │
│ ├── model // business logic
│ │ ├── api
│ │ │ └── HomeText.js
│ │ └── callback
│ │ └── Background.js
│ │
│ └── view // Per-page View, ViewModel files.
│ ├── top
│ │ ├── TopView.js
│ │ └── TopViewModel.js
│ └── home
│ ├── HomeView.js
│ └── HomeViewModel.js
│
└── __tests__ // Unit Test directory
└── model
└── default empty
流程图

命令
npm start
- 根据 routing.json 生成必要的 View 和 ViewModel 类。
npm run generate
npm run build -- --env="prd"
npm test
JSON 配置项
stage.json
名称 | 值类型 | 默认值 | 说明 |
---|
width | number | 240 | 设置显示区域的宽度。 |
height | number | 240 | 设置显示区域的高度。 |
fps | number | 12 | 每秒绘制的次数。 |
Option settings
名称 | 值类型 | 默认值 | 说明 |
---|
base | string | empty | 如果在请求时未设置URL,则要设置。 |
fullScreen | boolean | false | 全屏绘制 |
tagId | string | null | 值为你希望在 DOM 中绘制位置的容器 ID。 |
bgColor | array | null | RGBA 值在 0-255 范围内选择。 |
config.json
| 可以为每个环境设置不同的变量值。用`all`设置的值在所有环境中都可用。
名称 | 值类型 | 默认值 | 说明 |
---|
spa | boolean | true | 作为一个单页应用程序,可以通过URL来控制场景。 |
loading .callback | string | Loading | 设置是否展示屏幕过渡的准备工作完成之前的加载页。调用类的开始和结束函数作为回调。 |
gotoView .callback | string or array | ["callback.Background"] | 你可以指定在 `gotoView` 函数完成后回调的类。 |
routing.json
路由声明可以使用英文字母、数字、斜线、连字符和下划线。其对应的大驼峰名称包含斜线、连字符和下划线,作为键使用访问对应的视图类。
Example
在下面的例子中,`https://example.com/quest/list` 可被访问,其上下文被设置为 `QuestListView.js`。
{
"quest/list": {
"requests": []
}
}
子配置项
名称 | 值类型 | 默认值 | 说明 |
---|
private | boolean | false | 这用于控制SPA模式下的访问权限;如果设置为真,在 redirect 中设置的视图将被加载。 |
redirect | string | empty | 当 private 为真时,这里设置的页面将被加载。如果没有设置,将加载 TopView。 |
requests | array | null | 在访问视图之前,向指定的地址发送一个请求。收到的信息将被设置在 next2d.fw.response 中,以 name 作为键。 |
可在 "request" 中设置的属性。
名称 | 值类型 | 默认值 | 说明 |
---|
type | string | content | 此属性有以下可选值,`json`、`content`、`image` 和 `custom`。 |
path | string | empty | 从 config.json 中获取包含在 {{****}} 中的字符串值。 例如,{{ api.endPoint }}path/to/api |
name | string | empty | name 被设置后,作为在 Response Map 中检索数据的键。 |
cache | boolean | false | 缓存 name 为键、对应收到数据的值 |
callback | string or array | null | 你可以指定在请求完成后回调的类。该值将被设置为指定类构造函数的第一个参数,并被接管。 |
class | string | empty | 你可以指定执行请求的类。(只有当 type 为 custom 时才会被调用) |
access | string | public | 你可以指定执行请求函数的访问权限,可以设置为 `public` 或 `static`。(只有当 type 为 custom 时才会被调用) |
method | string | empty | 你可以指定一个函数来执行请求。(只有当 type 为 custom 时才会被调用) |