mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
43 lines
878 B
JavaScript
43 lines
878 B
JavaScript
export var behavior = Behavior({
|
|
created: function created() {
|
|
var _this = this;
|
|
|
|
if (!this.$options) {
|
|
return;
|
|
}
|
|
|
|
var cache = {};
|
|
|
|
var _this$$options = this.$options(),
|
|
computed = _this$$options.computed;
|
|
|
|
var keys = Object.keys(computed);
|
|
|
|
this.calcComputed = function () {
|
|
var needUpdate = {};
|
|
keys.forEach(function (key) {
|
|
var value = computed[key].call(_this);
|
|
|
|
if (cache[key] !== value) {
|
|
cache[key] = needUpdate[key] = value;
|
|
}
|
|
});
|
|
return needUpdate;
|
|
};
|
|
},
|
|
attached: function attached() {
|
|
this.set();
|
|
},
|
|
methods: {
|
|
// set data and set computed data
|
|
set: function set(data, callback) {
|
|
if (data) {
|
|
this.setData(data, callback);
|
|
}
|
|
|
|
if (this.calcComputed) {
|
|
this.setData(this.calcComputed());
|
|
}
|
|
}
|
|
}
|
|
}); |