Index

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

名称值类型默认值说明
widthnumber240设置显示区域的宽度。
heightnumber240设置显示区域的高度。
fpsnumber12每秒绘制的次数。
Option settings
名称值类型默认值说明
basestringempty如果在请求时未设置URL,则要设置。
fullScreenbooleanfalse全屏绘制
tagIdstringnull值为你希望在 DOM 中绘制位置的容器 ID。
bgColorarraynullRGBA 值在 0-255 范围内选择。

config.json

| 可以为每个环境设置不同的变量值。用`all`设置的值在所有环境中都可用。

名称值类型默认值说明
spabooleantrue作为一个单页应用程序,可以通过URL来控制场景。
loading.callbackstringLoading设置是否展示屏幕过渡的准备工作完成之前的加载页。调用类的开始和结束函数作为回调。
gotoView.callbackstring or array["callback.Background"]你可以指定在 `gotoView` 函数完成后回调的类。

routing.json

路由声明可以使用英文字母、数字、斜线、连字符和下划线。其对应的大驼峰名称包含斜线、连字符和下划线,作为键使用访问对应的视图类。

Example

在下面的例子中,`https://example.com/quest/list` 可被访问,其上下文被设置为 `QuestListView.js`。

{
  "quest/list": {
    "requests": []
  }
}

子配置项

名称值类型默认值说明
privatebooleanfalse这用于控制SPA模式下的访问权限;如果设置为真,在 redirect 中设置的视图将被加载。
redirectstringempty当 private 为真时,这里设置的页面将被加载。如果没有设置,将加载 TopView。
requestsarraynull在访问视图之前,向指定的地址发送一个请求。收到的信息将被设置在 next2d.fw.response 中,以 name 作为键。

可在 "request" 中设置的属性。

名称值类型默认值说明
typestringcontent此属性有以下可选值,`json`、`content`、`image` 和 `custom`。
pathstringempty从 config.json 中获取包含在 {{****}} 中的字符串值。 例如,{{ api.endPoint }}path/to/api
namestringemptyname 被设置后,作为在 Response Map 中检索数据的键。
cachebooleanfalse缓存 name 为键、对应收到数据的值
callbackstring or arraynull你可以指定在请求完成后回调的类。该值将被设置为指定类构造函数的第一个参数,并被接管。
classstringempty你可以指定执行请求的类。(只有当 type 为 custom 时才会被调用)
accessstringpublic你可以指定执行请求函数的访问权限,可以设置为 `public` 或 `static`。(只有当 type 为 custom 时才会被调用)
methodstringempty你可以指定一个函数来执行请求。(只有当 type 为 custom 时才会被调用)