解决Vue.Draggable在Vue新版3.2.32上运行报错“Cannot set properties of null (setting '__draggable_context')”的问题。

This commit is contained in:
vdpAdmin 2022-05-13 14:59:19 +08:00
parent 18870a2d95
commit b9e861d8f7
9 changed files with 78 additions and 58 deletions

View File

@ -4259,7 +4259,7 @@ function insertNodeAt(fatherNode, node, position) {
// EXTERNAL MODULE: ./src/util/console.js // EXTERNAL MODULE: ./src/util/console.js
var console = __webpack_require__("dbf1"); var util_console = __webpack_require__("dbf1");
// EXTERNAL MODULE: ./node_modules/core-js/modules/es.array.reduce.js // EXTERNAL MODULE: ./node_modules/core-js/modules/es.array.reduce.js
var es_array_reduce = __webpack_require__("13d5"); var es_array_reduce = __webpack_require__("13d5");
@ -4460,9 +4460,15 @@ function _createClass(Constructor, protoProps, staticProps) {
var getHtmlElementFromNode = function getHtmlElementFromNode(_ref) { //const getHtmlElementFromNode = ({ el }) => el;
var el = _ref.el; var getHtmlElementFromNode = function getHtmlElementFromNode(node) {
return el; var el = node.el || Array.isArray(node.children) && node.children[0].el.parentNode;
if (!el) {
console.error("使用 transition-group , 需要在slot中template内至少2层html标签");
}
return el || {};
}; };
var addContext = function addContext(domElement, context) { var addContext = function addContext(domElement, context) {
@ -4474,13 +4480,13 @@ var getContext = function getContext(domElement) {
}; };
var componentStructure_ComponentStructure = /*#__PURE__*/function () { var componentStructure_ComponentStructure = /*#__PURE__*/function () {
function ComponentStructure(_ref2) { function ComponentStructure(_ref) {
var _ref2$nodes = _ref2.nodes, var _ref$nodes = _ref.nodes,
header = _ref2$nodes.header, header = _ref$nodes.header,
defaultNodes = _ref2$nodes.default, defaultNodes = _ref$nodes.default,
footer = _ref2$nodes.footer, footer = _ref$nodes.footer,
root = _ref2.root, root = _ref.root,
realList = _ref2.realList; realList = _ref.realList;
_classCallCheck(this, ComponentStructure); _classCallCheck(this, ComponentStructure);
@ -4783,7 +4789,7 @@ var draggableComponent = Object(external_commonjs_vue_commonjs2_vue_root_Vue_["d
}, },
created: function created() { created: function created() {
if (this.list !== null && this.modelValue !== null) { if (this.list !== null && this.modelValue !== null) {
console["a" /* console */].error("modelValue and list props are mutually exclusive! Please set one or another."); util_console["a" /* console */].error("modelValue and list props are mutually exclusive! Please set one or another.");
} }
}, },
mounted: function mounted() { mounted: function mounted() {
@ -4884,6 +4890,7 @@ var draggableComponent = Object(external_commonjs_vue_commonjs2_vue_root_Vue_["d
spliceList: function spliceList() { spliceList: function spliceList() {
var _arguments = arguments; var _arguments = arguments;
// @ts-ignore
var spliceList = function spliceList(list) { var spliceList = function spliceList(list) {
return list.splice.apply(list, _toConsumableArray(_arguments)); return list.splice.apply(list, _toConsumableArray(_arguments));
}; };
@ -4937,7 +4944,8 @@ var draggableComponent = Object(external_commonjs_vue_commonjs2_vue_root_Vue_["d
} }
removeNode(evt.item); removeNode(evt.item);
var newIndex = this.getVmIndexFromDomIndex(evt.newIndex); var newIndex = this.getVmIndexFromDomIndex(evt.newIndex); // @ts-ignore
this.spliceList(newIndex, 0, element); this.spliceList(newIndex, 0, element);
var added = { var added = {
element: element, element: element,
@ -4958,7 +4966,8 @@ var draggableComponent = Object(external_commonjs_vue_commonjs2_vue_root_Vue_["d
var _this$context = this.context, var _this$context = this.context,
oldIndex = _this$context.index, oldIndex = _this$context.index,
element = _this$context.element; element = _this$context.element; // @ts-ignore
this.spliceList(oldIndex, 1); this.spliceList(oldIndex, 1);
var removed = { var removed = {
element: element, element: element,

File diff suppressed because one or more lines are too long

View File

@ -4268,7 +4268,7 @@ function insertNodeAt(fatherNode, node, position) {
// EXTERNAL MODULE: ./src/util/console.js // EXTERNAL MODULE: ./src/util/console.js
var console = __webpack_require__("dbf1"); var util_console = __webpack_require__("dbf1");
// EXTERNAL MODULE: ./node_modules/core-js/modules/es.array.reduce.js // EXTERNAL MODULE: ./node_modules/core-js/modules/es.array.reduce.js
var es_array_reduce = __webpack_require__("13d5"); var es_array_reduce = __webpack_require__("13d5");
@ -4469,9 +4469,15 @@ function _createClass(Constructor, protoProps, staticProps) {
var getHtmlElementFromNode = function getHtmlElementFromNode(_ref) { //const getHtmlElementFromNode = ({ el }) => el;
var el = _ref.el; var getHtmlElementFromNode = function getHtmlElementFromNode(node) {
return el; var el = node.el || Array.isArray(node.children) && node.children[0].el.parentNode;
if (!el) {
console.error("使用 transition-group , 需要在slot中template内至少2层html标签");
}
return el || {};
}; };
var addContext = function addContext(domElement, context) { var addContext = function addContext(domElement, context) {
@ -4483,13 +4489,13 @@ var getContext = function getContext(domElement) {
}; };
var componentStructure_ComponentStructure = /*#__PURE__*/function () { var componentStructure_ComponentStructure = /*#__PURE__*/function () {
function ComponentStructure(_ref2) { function ComponentStructure(_ref) {
var _ref2$nodes = _ref2.nodes, var _ref$nodes = _ref.nodes,
header = _ref2$nodes.header, header = _ref$nodes.header,
defaultNodes = _ref2$nodes.default, defaultNodes = _ref$nodes.default,
footer = _ref2$nodes.footer, footer = _ref$nodes.footer,
root = _ref2.root, root = _ref.root,
realList = _ref2.realList; realList = _ref.realList;
_classCallCheck(this, ComponentStructure); _classCallCheck(this, ComponentStructure);
@ -4792,7 +4798,7 @@ var draggableComponent = Object(external_commonjs_vue_commonjs2_vue_root_Vue_["d
}, },
created: function created() { created: function created() {
if (this.list !== null && this.modelValue !== null) { if (this.list !== null && this.modelValue !== null) {
console["a" /* console */].error("modelValue and list props are mutually exclusive! Please set one or another."); util_console["a" /* console */].error("modelValue and list props are mutually exclusive! Please set one or another.");
} }
}, },
mounted: function mounted() { mounted: function mounted() {
@ -4893,6 +4899,7 @@ var draggableComponent = Object(external_commonjs_vue_commonjs2_vue_root_Vue_["d
spliceList: function spliceList() { spliceList: function spliceList() {
var _arguments = arguments; var _arguments = arguments;
// @ts-ignore
var spliceList = function spliceList(list) { var spliceList = function spliceList(list) {
return list.splice.apply(list, _toConsumableArray(_arguments)); return list.splice.apply(list, _toConsumableArray(_arguments));
}; };
@ -4946,7 +4953,8 @@ var draggableComponent = Object(external_commonjs_vue_commonjs2_vue_root_Vue_["d
} }
removeNode(evt.item); removeNode(evt.item);
var newIndex = this.getVmIndexFromDomIndex(evt.newIndex); var newIndex = this.getVmIndexFromDomIndex(evt.newIndex); // @ts-ignore
this.spliceList(newIndex, 0, element); this.spliceList(newIndex, 0, element);
var added = { var added = {
element: element, element: element,
@ -4967,7 +4975,8 @@ var draggableComponent = Object(external_commonjs_vue_commonjs2_vue_root_Vue_["d
var _this$context = this.context, var _this$context = this.context,
oldIndex = _this$context.index, oldIndex = _this$context.index,
element = _this$context.element; element = _this$context.element; // @ts-ignore
this.spliceList(oldIndex, 1); this.spliceList(oldIndex, 1);
var removed = { var removed = {
element: element, element: element,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -18,7 +18,7 @@
"file-saver": "^2.0.5", "file-saver": "^2.0.5",
"mitt": "^3.0.0", "mitt": "^3.0.0",
"sortablejs": "1.14.0", "sortablejs": "1.14.0",
"vue": "3.2.26", "vue": "^3.2.32",
"vue3-quill": "^0.2.6" "vue3-quill": "^0.2.6"
}, },
"devDependencies": { "devDependencies": {

View File

@ -13,14 +13,16 @@
tag="transition-group" :component-data="{name: 'fade'}" tag="transition-group" :component-data="{name: 'fade'}"
handle=".drag-handler" @end="onDragEnd" @add="onDragAdd" @update="onDragUpdate" :move="checkMove"> handle=".drag-handler" @end="onDragEnd" @add="onDragAdd" @update="onDragUpdate" :move="checkMove">
<template #item="{ element: widget, index }"> <template #item="{ element: widget, index }">
<template v-if="'container' === widget.category"> <div class="transition-group-el">
<component :is="getWidgetName(widget)" :widget="widget" :designer="designer" :key="widget.id" :parent-list="designer.widgetList" <template v-if="'container' === widget.category">
:index-of-parent-list="index" :parent-widget="null"></component> <component :is="getWidgetName(widget)" :widget="widget" :designer="designer" :key="widget.id" :parent-list="designer.widgetList"
</template> :index-of-parent-list="index" :parent-widget="null"></component>
<template v-else> </template>
<component :is="getWidgetName(widget)" :field="widget" :designer="designer" :key="widget.id" :parent-list="designer.widgetList" <template v-else>
:index-of-parent-list="index" :parent-widget="null" :design-state="true"></component> <component :is="getWidgetName(widget)" :field="widget" :designer="designer" :key="widget.id" :parent-list="designer.widgetList"
</template> :index-of-parent-list="index" :parent-widget="null" :design-state="true"></component>
</template>
</div>
</template> </template>
</draggable> </draggable>
</div> </div>

View File

@ -16,9 +16,9 @@ export const generateCode = function(formJson, codeType= 'vue') {
<body> <body>
<div id="app"> <div id="app">
<v-form-render :form-json="formJson" :form-data="formData" :option-data="optionData" ref="vFormRef"> <v-form-render :form-json="formJson" :form-data="formData" :option-data="optionData" ref="vFormRef">
</v-form-render> </v-form-render>
<el-button type="primary" @click="submitForm">Submit</el-button> <el-button type="primary" @click="submitForm">Submit</el-button>
</div> </div>
<script src="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/3.2.30/vue.global.min.js"></script> <script src="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/3.2.30/vue.global.min.js"></script>