tdesign-mobile-vue
Version:
tdesign-mobile-vue
65 lines (59 loc) • 2.78 kB
JavaScript
/**
* tdesign v1.9.3
* (c) 2025 TDesign Group
* @license MIT
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var kebabCase = require('../_chunks/dep-6df33aaf.js');
require('../_chunks/dep-3d4c38f1.js');
require('../_chunks/dep-afa9f3f2.js');
require('../_chunks/dep-2f809ed9.js');
require('@babel/runtime/helpers/typeof');
require('../_chunks/dep-ae809b86.js');
require('../_chunks/dep-757b152c.js');
require('../_chunks/dep-2b08c0a6.js');
require('../_chunks/dep-5be9198d.js');
function useVModel(value, modelValue, defaultValue, onChange) {
var propName = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : "value";
var _getCurrentInstance = vue.getCurrentInstance(),
emit = _getCurrentInstance.emit,
vnode = _getCurrentInstance.vnode;
var internalValue = vue.ref();
internalValue.value = defaultValue;
var vProps = vnode.props || {};
var isVM = Object.prototype.hasOwnProperty.call(vProps, "modelValue") || Object.prototype.hasOwnProperty.call(vProps, "model-value");
var isVMP = Object.prototype.hasOwnProperty.call(vProps, propName) || Object.prototype.hasOwnProperty.call(vProps, kebabCase.kebabCase(propName));
if (isVMP || typeof value.value !== "undefined") {
return [value, function (newValue) {
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
emit === null || emit === void 0 || emit.apply(void 0, ["update:".concat(propName), newValue].concat(args));
onChange === null || onChange === void 0 || onChange.apply(void 0, [newValue].concat(args));
}];
}
if (isVM || typeof modelValue.value !== "undefined") {
return [modelValue, function (newValue) {
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
args[_key2 - 1] = arguments[_key2];
}
emit === null || emit === void 0 || emit.apply(void 0, ["update:modelValue", newValue].concat(args));
onChange === null || onChange === void 0 || onChange.apply(void 0, [newValue].concat(args));
}];
}
return [internalValue, function (newValue) {
internalValue.value = newValue;
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
args[_key3 - 1] = arguments[_key3];
}
onChange === null || onChange === void 0 || onChange.apply(void 0, [newValue].concat(args));
}];
}
var UPDATE_MODEL = "update:modelValue";
var UPDATE_VALUE = "update:value";
exports.UPDATE_MODEL = UPDATE_MODEL;
exports.UPDATE_VALUE = UPDATE_VALUE;
exports["default"] = useVModel;
//# sourceMappingURL=useVModel.js.map