程序员

select 默认选中空白解决方案

2018-11-23  本文已影响0人  yong_zai

一. 普通写法

  <select class=persons-select autocomplete=off>
    <option>政治</option>
    <option>经济</option>
    <option selected>文化</option>
  </select>

二.vue中的写法(默认选择空白解决方案)

<body>
  <div id="app">
    <select autocomplete="off" v-model="contactPersonSelected">
      <option v-for="option in contactPersonOptions" v-bind:value="option.id">{{option.name}}</option>
    </select>
  </div>
  <script>
    var app = new Vue({
      el: "#app",
      data: {
        contactPersonSelected: "",
        contactPersonOptions: [
          { id: 0, name: "张三丰" },
          { id: 1, name: "周伯通" },
          { id: 2, name: "欧阳锋" },
          { id: 3, name: "独孤求败" },
        ],
      },

      created() {
        this.contactPersonSelected = this.contactPersonOptions[3].id
      }

    })

  </script>
</body>
上一篇 下一篇

猜你喜欢

热点阅读