Module
FXS code can be written in the 'fxml' tag <fxs>in the 'fxml' file, or in a file with the '.fxs' suffix.
# 1. module
Each '.fxs' file and the <fxs>'' tag is a separate module.
Each module has its own independent scope. That is, variables and functions defined in one module are private by default and invisible to other modules.
A module that wants to expose its internal private variables and functions can only be implemented through 'module.exports'.
# .fxs file
# Sample code
The above example writes FXS code in the '/pages/comm.fxs' file. The '.fxs' file can be referenced by other '.fxs' files or the '' tag in FXML<fxs>.
# module object
Each 'fxs' module has a built-in 'module' object.
# property
- 'exports': This property allows you to share the module's private variables and functions.
# Sample code
Page output:
# require function
To reference other 'fxs' file modules in the '.fxs' module, you can use the 'require' function.
When citing, pay attention to the following points:
- Only '.fxs' file modules can be referenced and relative paths must be used.
- 'fxs' modules are singletons, and 'fxs' modules are automatically initialized to singleton objects the first time they are referenced. Multiple pages, multiple places, multiple references, using the same 'fxs' module object.
- If an 'fxs' module has not been referenced since it was defined, the module will not be parsed and run.
# Sample code
Console output:
# '<fxs>' hashtag
| Property Name | Type | The default value is | Description |
|---|---|---|---|
| module | String | The <fxs>module name of the current '' tag. Required fields. | |
| src | String | Reference the relative path of the '.fxs' file. Valid only if the label is a single-closed label or if the contents of the label are empty. |
# module attribute
The module attribute is the <fxs>module name of the current '' tag. Within a single fxml file, it is recommended that its values be unique. Duplicate module names are overwritten in order (the latter overrides the former). The fxs module names between different files are not overwritten with each other.
The naming of module attribute values must conform to the following two rules:
- The first character must be: letter (a-zA-Z), underscore (_).
- The remaining characters can be: letters (a-zA-Z), underscores (_), numbers (0-9).
# Sample code
Page output:
The above example declares a module named 'foo' that exposes the 'some_msg' variable for use on the current page.
# src attribute
The src attribute can be used to reference other 'fxs' file modules.
When citing, pay attention to the following points:
- Only the '.wxs' file module can be referenced and a relative path must be used.
- 'wxs' modules are all singletons, and 'wxs' modules are automatically initialized to singleton objects the first time they are referenced. Multiple pages, multiple places, multiple references, all using the same 'wxs' module object.
- If a 'wxs' module has not been referenced since it was defined, the module will not be parsed and run.
# Sample code
Page output:
The above example references the '/page/comm.fxs' module in the file <fxs>'/page/index/index/index.fxml' with the '/page/index/index.fxml' tag.
# 2. Precautions
- The '<fxs>' module can only be accessed in the FXML file where the module is defined. When using <include>'' or <import>'', the '<fxs>' module is not introduced into the corresponding FXML file.
- In <template>the '' tag, only the '<template>' module defined in the FXML file that defines the '' can be used<fxs>.