From 1362bae57d54d163c243a324b6c3fbea8c588df3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=A5=95?= Date: Wed, 21 Mar 2018 10:54:33 +0800 Subject: [PATCH] Popover: fix error when reference comes before popover (#10273) --- packages/popover/src/directive.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/popover/src/directive.js b/packages/popover/src/directive.js index 3ad8d9422..0bed851dd 100644 --- a/packages/popover/src/directive.js +++ b/packages/popover/src/directive.js @@ -1,7 +1,16 @@ -export default { - bind(el, binding, vnode) { - // vue中 v-popover:argument 和 v-popover="variate|| expression"得到的binding数据是不同的。后者可以指向动态popver组件,可以极大的增强popover指令的灵活程度。 - const _ref = binding.expression ? binding.value : binding.arg; - vnode.context.$refs[_ref].$refs.reference = el; +const getReference = (el, binding, vnode) => { + const _ref = binding.expression ? binding.value : binding.arg; + const popper = vnode.context.$refs[_ref]; + if (popper) { + popper.$refs.reference = el; + } +}; + +export default { + bind(el, binding, vnode) { + getReference(el, binding, vnode); + }, + inserted(el, binding, vnode) { + getReference(el, binding, vnode); } };