@form-component/common-antd-vue
Version:
57 lines (50 loc) • 1.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useEffect = exports.useState = void 0;
var _vue = require("vue");
const useState = default_v => {
const state = (0, _vue.ref)(default_v);
return [state, v => {
state.value = v;
}];
};
exports.useState = useState;
const useEffect = (fn, array) => {
if (typeof array === undefined) {
(0, _vue.onRenderTracked)(() => {
fn();
});
(0, _vue.onRenderTriggered)(() => {
fn();
});
} else if (array instanceof Array) {
if (array.length === 0) {
(0, _vue.watchEffect)((...args) => {
fn(...args);
});
} else {
let callback = (0, _vue.ref)(null);
const fns = array.map(item => {
if (item.value === undefined) {
console.error('params must ref');
}
return () => item.value;
});
(0, _vue.watch)(fns, ([...args]) => {
// console.log(args)
callback.value = fn(args);
}, {
immediate: true
});
(0, _vue.onUnmounted)(() => {
// console.log('112233')
callback.value && callback.value();
});
}
} else {
console.error(`${array} is not array,please check your code!`);
}
};
exports.useEffect = useEffect;