props: {
/**
- 字符串类型 属性:buttonText 需要设置默认值
*/
"buttonText": {
type: String,
default: "点击触发"
}
},
/**- 组件内部变量声明
*/
data() {
return {}
},
/** - 属性变化监听器实现
*/
watch: {
"buttonText": {
/**- 这里监听属性变化,并进行组件内部更新
*/
handler(newButtonText: string) {
if (this.$el != null) {
let button = this.$el!.findViewWithTag("centerButton") as Button
if (!TextUtils.isEmpty(newButtonText)) {
button.setText(newButtonText)
}
}
},
immediate: false //创建时是否通过此方法更新属性,默认值为false
},
},
- 这里监听属性变化,并进行组件内部更新
- 组件内部变量声明