Constructor

Constructor

Parameter Description

ParameterType

Required

Description
dataObjectNoComponent internal status.
propsObjectNoSet default for incoming data.
onInitFunctionNoComponent lifecycle function, trigger on component creation.
deriveDataFromPropsFunctionNoComponent lifecycle function, trigger on component creation and update.
didMountFunctionNoComponent lifecycle function, trigger on component creation completion.
didUpdateFunctionNoComponent lifecycle function, trigger on component update completion.
didUnmountFunctionNoComponent lifecycle function, trigger on component deletion.
mixinsArrayNoCode reuse mechanism between components.
methodsObjectNoComponent method, can be event response function or any customized method.

Sample Code

js sample code:

copy
Component({
  mixins:[{ didMount() {}, }],
  data: {y:2},
  props:{x:1},
  didUpdate(prevProps,prevData){},
  didUnmount(){},
  methods:{
    onMyClick(ev){
      my.alert({});
      this.props.onXX({ ...ev, e2:1});
    },
  },
})

Component Instance Attribute List

Parameter Description

Property

TypeDescription
dataObjectComponent internal data.
propsObjectIncoming component attribute.
isStringComponent path.
$pageObjectComponent page instance.
$idNumberComponent id, can render value in component axml.

Sample Code

js sample code:

copy
// /components/xx/index.js
Component({
  didMount(){
    this.$page.xxCom = this; // this operation can load the component instance to the belonging page instance
    console.log(this.is);
    console.log(this.$page);
    console.log(this.$id);
  }
});

axml sample code:

copy
<!-- /components/xx/index.axml component id can directly render value in component axml -->
<view>{{$id}}</view>

json sample code:

copy
// /pages/index/index.json
{
  "usingComponents": {
  	"xx": "/components/xx/index"
  }
}

js sample code:

copy
Page({
  onReady() {
    console.log(this.xxCom); // can access all loaded components loaded onto the current page
  },
})

When the component is rendered on the page, execute the didMount callback, and the console has the following output:

copy
/components/xx/index
{$viewId: 51, route: "pages/index/index"}
1

Component Instance Method List

Method nameParameterDescrsiption
setDataObjectSetting data triggers view rendering.
$spliceDataObjectSetting data triggers view rendering.