The problem

In wechat applets, if the name of the parameter field passed to the component is “ID”, obtaining this.data.id in the component is not the real passed value.

The trigger condition

Wechat developer Tool version: 1.05.2108202

Base library version: 2.19.2

<testComponent id="{{4}}" info="{{4}}" />
<testComponent id="{{5}}" info="{{5}}" />
<testComponent id="{{6}}" info="{{6}}" />
Copy the code
// testComponent.js
Component({
    properties: {
        id: {
            type: Number.value: 0,},info: {
            type: Number.value: 0,}},lifetimes: {attached() {
            console.log(this.id, this.data.id, this.data.info, this); ,}}});Copy the code

This. id is printed sequentially, starting with 1, as a string. The guess is that keywords like key are used as indexes.

This.data. id will print the default value 0.

This.data. info just changes the field name (not the ID) and prints the value as usual.

conclusion

Component inside, as far as possible do not take “ID” field name, to avoid conflicts.