目录

What should I do if the input parameter is empty due to undefined properties when customizing a component?

Symptom

If properties is undefined, the data printed in attached will not contain the properties passed from the parent component.

The following code is an example.

Component({
  data: {
    id: 100,
  },
  lifetimes: {
    attached () {
      console.info('Component', this.properties)
    },
    detached () {
      console.info('[Component] detached');
    }
  },
});

Solution

Add the corresponding property name to properties.

properties:{
  compName: {
    type: String,
    value: ''
  },
},