@opentiny/vue-renderless
Version:
An enterprise-class UI component library, support both Vue.js 2 and Vue.js 3, as well as PC and mobile.
60 lines (59 loc) • 1.62 kB
JavaScript
import "../chunk-G2ADBYYC.js";
import {
check,
filter,
getCheckedData,
getPluginOption,
getTreeData,
mounted,
nodeClick,
watchValue,
getChildValue
} from "./index";
const api = ["state", "check", "filter", "nodeClick"];
const renderless = (props, { reactive, computed, watch, onMounted }, { vm, emit }) => {
const api2 = {};
const state = reactive({
childrenName: computed(() => props.treeOp.props && props.treeOp.props.children || "children"),
currentKey: props.modelValue,
defaultCheckedKeys: [],
remoteData: [],
treeData: props.treeOp.data,
modelValue: []
});
Object.assign(api2, {
state,
check: check({ props, vm, emit }),
filter: filter({ vm }),
getCheckedData: getCheckedData({ props, state }),
getPluginOption: getPluginOption({ api: api2, props, state }),
getTreeData: getTreeData({ props, state }),
mounted: mounted({ api: api2, state, props, vm }),
nodeClick: nodeClick({ props, vm, emit }),
watchValue: watchValue({ api: api2, props, vm, state }),
getChildValue: getChildValue()
});
watch(
() => props.treeOp.data,
(data) => data && (state.treeData = data),
{ immediate: true, deep: true }
);
watch(
() => props.modelValue,
() => {
if (props.multiple && Array.isArray(props.modelValue)) {
state.modelValue = [...props.modelValue];
} else {
state.modelValue = props.modelValue;
}
},
{ immediate: true, deep: true }
);
watch(() => state.modelValue, api2.watchValue);
onMounted(api2.mounted);
return api2;
};
export {
api,
renderless
};