From ef948ac5a2654c13ecb5e3e291a4fd321ac91ee8 Mon Sep 17 00:00:00 2001 From: qiang Date: Fri, 19 Feb 2021 11:42:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E7=BB=84=E4=BB=B6=20dataset=20?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BC=BA=E5=A4=B1=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20question/117206?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/helpers/index.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/core/helpers/index.js b/src/core/helpers/index.js index 79052bd14..0b013a236 100644 --- a/src/core/helpers/index.js +++ b/src/core/helpers/index.js @@ -31,7 +31,6 @@ export function normalizeDataset (dataset = {}) { const len = key.length if (key.substr(0, 1) === 'v' && (len === 9 || len === 10)) { delete result[key] - break } } } @@ -41,13 +40,28 @@ export function normalizeDataset (dataset = {}) { export function getTargetDataset (target) { let dataset = {} - if (target.__vue__) { - const $attrs = target.__vue__.$attrs + const vm = target.__vue__ + function updateDataset (vm, force) { + const $attrs = vm.$attrs for (const key in $attrs) { if (key.startsWith('data-')) { - dataset[camelize(key.substr(5))] = $attrs[key] + const newKey = camelize(key.substr(5)) + const value = $attrs[key] + dataset[newKey] = force ? value : dataset[newKey] || value } } + } + if (vm) { + let $child = vm + while ($child && $child.$el === target) { + updateDataset($child) + $child = $child.$children[0] + } + let $parent = vm.$parent + while ($parent && $parent.$el === target) { + updateDataset($parent, true) + $parent = $parent.$parent + } } else { dataset = target.dataset || {} } -- GitLab