What is the difference between properties and data in Mini Program?

I think properties is written in the same way except for a few more parameters. What is the specific difference between the two? why should it be divided into two?


do you mean properties and data of the component?

properties is a parameter that can be passed externally when using a component, that is, the caller can modify the property externally, but not if it is placed in data .

for example, if there is a component called titleContainer , there is a title attribute in properties :

.
//...
properties: {
        title: {
            type: String,
            value: 'default title',
        }
    }
//...

use components in the page:

<titleContainer title="{{otherTitle}}"></titleContainer>

but if this title is placed in data , it cannot be modified in this way.

Menu