Repository: vuejs/vue
Pull request: fix #6209, selected option not updated properly under IE11

<!--
Please make sure to read the Pull Request Guidelines:
https://github.com/vuejs/vue/blob/dev/.github/CONTRIBUTING.md#pull-request-guidelines
-->

<!-- PULL REQUEST TEMPLATE -->
<!-- (Update "[ ]" to "[x]" to check a box) -->

**What kind of change does this PR introduce?** (check at least one)

- [x] Bugfix
- [ ] Feature
- [ ] Code style update
- [ ] Refactor
- [ ] Build-related changes
- [ ] Other, please describe:

**Does this PR introduce a breaking change?** (check one)

- [ ] Yes
- [x] No

If yes, please describe the impact and migration path for existing applications:

**The PR fulfills these requirements:**

- [x] It's submitted to the `dev` branch for v2.x (or to a previous version branch), _not_ the `master` branch
- [x] When resolving a specific issue, it's referenced in the PR's title (e.g. `fix #xxx[,#xxx]`, where "xxx" is the issue number)
- [x] All tests are passing: https://github.com/vuejs/vue/blob/dev/.github/CONTRIBUTING.md#development-setup
- [ ] New/updated tests are included

If adding a **new feature**, the PR's description includes:
- [ ] A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

**Other information:**

[https://github.com/vuejs/vue/issues/6209#issuecomment-317715265](https://github.com/vuejs/vue/issues/6209#issuecomment-317715265)

Changed files:
filename: src/platforms/web/runtime/directives/model.js
patch: @@ -22,14 +22,7 @@ if (isIE9) {
 export default {
   inserted (el, binding, vnode) {
     if (vnode.tag === 'select') {
-      const cb = () => {
-        setSelected(el, binding, vnode.context)
-      }
-      cb()
-      /* istanbul ignore if */
-      if (isIE || isEdge) {
-        setTimeout(cb, 0)
-      }
+      setSelected(el, binding, vnode.context)
       el._vOptions = [].map.call(el.options, getValue)
     } else if (vnode.tag === 'textarea' || isTextInputType(el.type)) {
       el._vModifiers = binding.modifiers
@@ -67,37 +60,45 @@ export default {
 }
 
 function setSelected (el, binding, vm) {
-  const value = binding.value
-  const isMultiple = el.multiple
-  if (isMultiple && !Array.isArray(value)) {
-    process.env.NODE_ENV !== 'production' && warn(
-      `<select multiple v-model="${binding.expression}"> ` +
-      `expects an Array value for its binding, but got ${
-        Object.prototype.toString.call(value).slice(8, -1)
-      }`,
-      vm
-    )
-    return
-  }
-  let selected, option
-  for (let i = 0, l = el.options.length; i < l; i++) {
-    option = el.options[i]
-    if (isMultiple) {
-      selected = looseIndexOf(value, getValue(option)) > -1
-      if (option.selected !== selected) {
-        option.selected = selected
-      }
-    } else {
-      if (looseEqual(getValue(option), value)) {
-        if (el.selectedIndex !== i) {
-          el.selectedIndex = i
+  const cb = () => {
+    const value = binding.value
+    const isMultiple = el.multiple
+    if (isMultiple && !Array.isArray(value)) {
+      process.env.NODE_ENV !== 'production' && warn(
+        `<select multiple v-model="${binding.expression}"> ` +
+        `expects an Array value for its binding, but got ${
+          Object.prototype.toString.call(value).slice(8, -1)
+        }`,
+        vm
+      )
+      return
+    }
+    let selected, option
+    for (let i = 0, l = el.options.length; i < l; i++) {
+      option = el.options[i]
+      if (isMultiple) {
+        selected = looseIndexOf(value, getValue(option)) > -1
+        if (option.selected !== selected) {
+          option.selected = selected
+        }
+      } else {
+        if (looseEqual(getValue(option), value)) {
+          if (el.selectedIndex !== i) {
+            el.selectedIndex = i
+          }
+          return
         }
-        return
       }
     }
+    if (!isMultiple) {
+      el.selectedIndex = -1
+    }
   }
-  if (!isMultiple) {
-    el.selectedIndex = -1
+
+  cb()
+  /* istanbul ignore if */
+  if (isIE || isEdge) {
+    setTimeout(cb, 0)
   }
 }