Vuejs禁用了选定的下拉选项?

时间:2016-02-24 06:31:19

标签: jquery vue.js

我有一个数组selected,它包含一组选定的选项。我想使用该数组为这些选项添加disabled属性。

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title> Vue-js Control </title>
    </head>
    <body>
        <div id="demo">
            <select v-model="selected" multiple>
              <option v-for="option in options" v-bind:value="option.value">
                {{ option.text }}
              </option>
            </select>
            <span>Selected: {{ selected }}</span>
        </div>

    <script type="text/javascript" src='http://cdnjs.cloudflare.com/ajax/libs/vue/1.0.16/vue.min.js'></script>
    <script type="text/javascript">
    new Vue({
        el: '#demo',
        data: {
            selected: ['A','B','D'],
            options: [
              { text: 'One', value: 'A' },
              { text: 'Two', value: 'B' },
              { text: 'Three', value: 'C' },
              { text: 'Four', value: 'D' },
              { text: 'Five', value: 'E' },
              { text: 'Six', value: 'F' },
              { text: 'Seven', value: 'G' },
            ]
        }
    });
    </script>
</body>

1 个答案:

答案 0 :(得分:11)

您想要禁用所选数组中的所有选项吗?

<option v-for="option in options" :disabled="selected.includes(option.value)" :value="option.value">