definition segment | type | Is it necessary to fill out | describe |
properties | Object Map | no | External properties of a component are a map of property names to property settings |
data | Object | no | Component's internal data, and properties Template rendering for components together |
observers | Object | no | |
methods | Object | no | Component, including event response functions and arbitrary custom methods. For the use of event response function, see Inter-component communication and events |
behaviors | String Array | no | |
created | Function | no | Component lifecycle function - executes when the component instance has just been created, noting that it cannot be called at this time setData |
attached | Function | no | Component life cycle function - executed when component instance enters page node tree |
ready | Function | no | Component Life Cycle Function - Executed after component layout is complete |
detached | Function | no | Component Lifecycle Function - Executes when component instance is removed from page node tree |
relations | Object | no | |
externalClasses | String Array | no | |
options | Object Map | no | Some options (specific option settings are covered when the features are described in the documentation, not listed here) |
lifetimes | Object | no | |
pageLifetimes | Object | no | The lifecycle declaration object for the page on which the component resides, see Component life cycle |
observer
Through this Access. Components contain common properties and methods.Attribute name | type | describe |
is | String | Component file path |
id | String | Node id |
dataset | String | Node dataset |
data | Object | Component data,Including internal data and attribute values |
properties | Object | Component data,Including internal data and attribute values(data Consistent) |
Method name | parameter | describe |
setData | Object newData | Set up data and perform view-layer rendering |
triggerEvent | String name, Object detail, Object options | |
createSelectorQuery | - | |
createIntersectionObserver | - | |
SelecComponent | String selector | Select the component instance node using the selector and return the first component instance object that matches wx://component-export Impact |
selectAllComponents | String selector | Select the component instance node using the selector and return an array of matched component instance objects wx://component-export Impact |
selectOwnerComponent | String selector | Selects the component instance of the current component node (that is, the reference to the component) and returns its component instance object wx://component-export Impact |
getRelationNodes | String relationKey | |
hasBehavior | Object behavior | Checks if the component has a behaviour (the check recursively checks all behaviours that have been introduced directly or indirectly). |
Component({behaviors: [],// Property definition (see below for details)properties: {myProperty: { // Attribute nametype: String,value: ''},myProperty2: String // Simplified definition},data: {}, // Private data, available for template renderinglifetimes: {// Life cycle function, can be a function, or a method name defined in the methods sectionattached: function () { },moved: function () { },detached: function () { },},// Life cycle function, can be a function, or a method name defined in the methods sectionattached: function () { }, // The attached declaration here is overwritten by the declaration in the lifetimes fieldready: function() { },pageLifetimes: {// Life Cycle Function for the Page on which the component is locatedshow: function () { },hide: function () { },resize: function () { },},methods: {onMyButtonTap: function(){this.setData({// The method of updating properties and data is similar to that of updating page data})},// The internal method recommends starting with an underscore_myPrivateMethod: function(){// Here will be data.A[0].B Set to 'myPrivateData'this.setData({'A[0].B': 'myPrivateData'})},_propertyChange: function(newVal, oldVal) {}}})
Definition segment | type | Is it necessary to fill out | describe |
type | - | yes | Type of attribute |
value | - | no | The initial value of the |
observer | Function | no | Callback function when attribute value changes |
Component({properties: {min: {type: Number,value: 0},min: {type: Number,value: 0,observer: function(newVal, oldVal) {// When property values change}},lastLeaf: {// This property can be Number 、 String 、 Boolean One of three types.type: Number,optionalTypes: [String, Object],value: 0}}})
<custom-comp min="1" max="5" />
this.data.min === 1 //truethis.data.Max === 5 // true
Definition segment | type | Is it necessary to fill out | describe |
properties | Object Map | No | Properties of the same component |
data | Object | No | Properties of the same component |
methods | Object | No | Same method as custom components |
behaviors | String Array | No | |
created | Function | No | Component Lifecycle Functions - executed when the component instance has just been created, note that setData cannot be called at this time. |
attached | Function | No | Component Lifecycle Functions - executed when the component instance enters the page node tree |
ready | Function | No | Component Lifecycle Functions - executed after the component layout is complete |
detached | Function | No | Component Lifecycle Functions - executed when the component instance is removed from the page node tree |
relations | Object | No | |
lifetimes | Object | No | |
pageLifetimes | Object | No | The lifecycle declaration object for the page on which the component resides, see Component Lifecycle |
// my-behavior.jsmodule.exports = Behavior({behaviors: [],properties: {myBehaviorProperty: {type: String}},data: {myBehaviorData: {}},attached: function(){},methods: {myBehaviorMethod: function(){}}})
Was this page helpful?