diff --git a/src/platforms/web/runtime/directives/model.js b/src/platforms/web/runtime/directives/model.js index e7c206fb5..5023ac5f0 100644 --- a/src/platforms/web/runtime/directives/model.js +++ b/src/platforms/web/runtime/directives/model.js @@ -32,7 +32,7 @@ export default { } } if (vnode.tag === 'select') { - setSelected(el, binding.value) + setSelected(el, binding, vnode.context) } else { if (!isAndroid) { el.addEventListener('compositionstart', onCompositionStart) @@ -45,16 +45,15 @@ export default { } }, componentUpdated (el, binding, vnode) { - const val = binding.value if (vnode.tag === 'select') { - setSelected(el, val) + setSelected(el, binding, vnode.context) // in case the options rendered by v-for have changed, // it's possible that the value is out-of-sync with the rendered options. // detect such cases and filter out values that no longer has a matchig // option in the DOM. const needReset = el.multiple - ? val.some(v => hasNoMatchingOption(v, el.options)) - : hasNoMatchingOption(val, el.options) + ? binding.value.some(v => hasNoMatchingOption(v, el.options)) + : hasNoMatchingOption(binding.value, el.options) if (needReset) { trigger(el, 'change') } @@ -62,10 +61,20 @@ export default { } } -function setSelected (el, value) { +function setSelected (el, binding, vm) { + const value = binding.value const isMultiple = el.multiple if (!isMultiple) { el.selectedIndex = -1 + } else if (!Array.isArray(value)) { + process.env.NODE_ENV !== 'production' && warn( + `' + }).$mount() + expect('