This document describes components API, the San module API
please refer to San API.
Initialization Arguments
data
Explanation
:
Component initialization data. Usually used in the component hydrate scenario.
Type
: Object
Usage
:
1 | var MyComponent = san.defineComponent({}); |
el
explanation
:
Component root element. Passing in this parameter means that the component’s template is not used as the view template, and the component view is automatically reversed by San. See here for more details.
type
: HTMLElement
code
:
1 | var MyComponent = san.defineComponent({}); |
transition
explanation
:
The transition animation controller for the component. See animation controller and animation controller creator for more details.
version
: >= 3.6.0
type
: Object
code
:
1 | var MyComponent = san.defineComponent({ |
Lifecycle hooks
The life cycle represents the survival process of the component, and the hook function is triggered when each process arrives. See lifecycle for more details.
compiled
explanation
:
The component view template is compiled. The compiled method on the component will be called.
inited
explanation
:
The component instance initialization is complete. The inited method on the component will be called.
created
explanation
:
The component element is created. The created method on the component will be called.
attached
explanation
:
The component has been attached to the page. The attached method on the component will be called.
detached`
explanation
:
The component is removed from the DOM. The detached method on the component will be called.
disposed
explanation
:
The component is removed from the DOM and components had destroyed. The disposed method on the component will be called.
updated
explanation
:
The component completes a refresh due to data changes. The updated method on the component will be called.
error
version
:>= 3.10.7
explanation
:
Called when an error from any descendent component is captured. The hook receives three arguments: the error, the component instance that triggered the error, and a string containing information on where the error was captured. The hook will stop the error from propagating further.
define Component
template
explanation
:
The view template for the component. see component template for more details.
type
: string
usage
:
1 | san.defineComponent({ |
filters
explanation
:
Declare which filters can be used in a component view template. see filter for more details.
type
: Object
usage
:
1 | san.defineComponent({ |
Warning
:
The filter method can access the component’s data through this.data
at runtime, however doing so can result in an implicit dependency on the data, causing the view to not update as the data changes. Therefore, the filter method should be a pure function with no side effects.
1 | var Bad = san.defineComponent({ |
components
explanation
:
Declare which types of subcomponents can be used in a component. see components for more details.
type
: Object
usage
:
1 | var AddForm = san.defineComponent({ |
computed
explanation
:
Declare the calculated data in the component. see computed data for more details.
type
: Object
usage
:
1 | san.defineComponent({ |
messages
explanation
:
declare how to handle subcomponent dispatch messages. see message for more details.
type
: Object
usage
:
1 | var Select = san.defineComponent({ |
initData
explanation
:
Return the initial data of the component instance. see init data for more details.
type
: function():Object
usage
:
1 | var MyApp = san.defineComponent({ |
trimWhitespace
Defines the trim mode for whitespace characters when parsing component templates.
- none(default) nothing
- blank clear blank text node
- all clear the leading and trailing whitespace characters of all text nodes.
version
: >= 3.2.5
type
: string
usage
:
1 | var MyApp = san.defineComponent({ |
delimiters
explanation
:
Define the separator for interpolation when parsing a component template. An array of 2 items with starting and ending delimiters.
default:
1 | ['{{', '}}'] |
version
: >= 3.5.0
type
: Array
usage
:
1 | var MyComponent = san.defineComponent({ |
transition (Deprecated)
Explanation
:
Transition animation controller that defines the root node of the component.
Version
: >= 3.3.0, < 3.6.0
Type
: Object
Usage
:
1 | var MyComponent = san.defineComponent({ |
updateMode
Explanation
:
This property specifies how the view should update. Currently only "optimized"
is supported. When this is set, s-for
directive updates the view using a more performance friendly method according to each browser, in this case DOM elements may not be correctly reused (but is faster).
Version
: >= 3.7.4
Type
: string
Usage
:
1 | var MyComponent = san.defineComponent({ |
aNode
Explanation
:
The parse result of .template
. To speed up initialization, template will not be compiled again during component instantiation if the .aNode
property exists. .aNode
is used by pre-compile optimization and typically generated by build tools, you are not required to include it in source codes. Use san-anode-utils to work with ANode.
Type
: Object
Usage
:
1 | var MyComponent = san.defineComponent({ |
aPack
Explanation
:
A compressed version of aNode
. aPack
has a much smaller size than aNode
and the decompression is faster than that parsing template
in place. Like aNode
, aPack
is used by pre-compile optimization and typically generated by build tools. Use san-anode-utils to work with aPack.
Version
: >= 3.9.0
Type
: Array
Usage
:
1 | var MyComponent = san.defineComponent({ |
Component Method
fire
description
: fire({string}eventName, {*}eventArgument)
explanation
:
Fire a custom event. San provides custom event functionality for components. Component developers can fire events through this method. Events can be bound in the view template by on-, or be listened to by the on method of the component instance. see customized event for more details.
usage
:
1 | var Label = san.defineComponent({ |
on
description
: on({string}eventName, {Function}eventListener)
explanation
:
Add a custom event listener. on is generally only used in components that are dynamically created using JavaScript. Subcomponents created through view template should be bound by on-. see dynamic child components for more details.
un
description
: un({string}eventName, {Function=}eventListener)
explanation
:
Remove event listener. Remote the listeners for all eventName events when the eventListener params is empty.
dispatch
description
: dispatch({string}name, {*}value)
explanation
:
Dispatch a message. The message will be passed up in the component tree util it encounters the first component that processes the message. The upper component declares the message to be processed by the component via message. The message is mainly used for communication between components with none owner upper components. see message for more details.
usage
:
1 | var SelectItem = san.defineComponent({ |
watch
description
: watch({string}dataName, {function({*}value)}listener)
explanation
:
Watch component’s data changes. Usually we use bindings to automatically update the corresponding data of the parent component when the child component data changes. watch is generally only used in components that are dynamically created using JavaScript. see dynamic child components for more details.
1 | san.defineComponent({ |
ref
description
: ref({string}name)
explanation
:
Get the subcomponents that define s-ref. see component tree for more details.
usage
:
1 | var AddForm = san.defineComponent({ |
slot
version
: >= 3.3.0
description
: {Array} slot({string=}name)
explanation
:
Get the node information of the component slot. The return value is an array, and the items in the array are node objects and usually only one. And there will be more that one node objects when if or for is applied in the slot declaration. The node objects include isScoped
, isInserted
, and children
property. see slot for more details.
attention
: do not make any modifications to the returned slot object. If you want to manipulate the view changes, please manipulate the data.
usage
:
1 | var Panel = san.defineComponent({ |
nextTick
explanation
:
San’s view update is asynchronous. After the component data is changed, the view will be updated in the next clock cycle. If you modify some data and want to do something after the DOM update, you need to use the nextTick
method.
usage
:
1 | const Component = san.defineComponent({ |