deguodaigou/utils/dist/mixins/observer/index.js
2019-12-14 09:20:48 +08:00

20 lines
608 B
JavaScript

import { behavior } from './behavior';
export function observe(vantOptions, options) {
const { watch } = vantOptions;
options.behaviors.push(behavior);
if (watch) {
const props = options.properties || {};
Object.keys(watch).forEach(key => {
if (key in props) {
let prop = props[key];
if (prop === null || !('type' in prop)) {
prop = { type: prop };
}
prop.observer = watch[key];
props[key] = prop;
}
});
options.properties = props;
}
}