component({
options: {
// 使用基础库内置的数据变化观测器
observers: true,
},
});
page({
options: {
// 使用基础库内置的数据变化观测器
observers: true,
},
});
function wrapcomponentoptions (options) {
// 运行时检测当前基础库版本是否已支持observers
if (my.caniuse('component.observers')) {
options.options = options.options || {};
options.options = {
observers: true,
};
} else {
// 开发者统一封装的observers功能
}
return options;
}
component(wrapcomponentoptions(
// 数据变化观测器
observers: {
"**": function(val) {
console.log(val);
}
}
));