早安,我是vue.js的新手,我想输入foo这样的值,如果我再次尝试选择它时被选择为禁用的话。问题是当我选择第二个时,例如bar我可以返回并选择第一个为foo。enter image description here 这是我的代码。
Vue.component('v-select', VueSelect.VueSelect)
new Vue({
el: '#app',
data: {
selected:"",
options: [{
id: 1,
label: 'foo'
},
{
id: 3,
label: 'bar'
},
{
id: 2,
label: 'baz'
},
],
}
})
body {
font-family: 'Source Sans Pro', 'Helvetica Neue', Arial, sans-serif;
}
h1 {
font-size: 26px;
font-weight: 600;
color: #2c3e5099;
text-rendering: optimizelegibility;
-moz-osx-font-smoothing: grayscale;
-moz-text-size-adjust: none;
}
#app {
max-width: 30em;
margin: 1em auto;
}
<script src="https://unpkg.com/babel-polyfill@latest/dist/polyfill.min.js"></script>
<script src="https://unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/vue@latest"></script>
<!-- use the latest release -->
<script src="https://unpkg.com/vue-select@latest"></script>
<div id="app">
<h1>Vue Select - Using v-model</h1>
<v-select multiple v-model="selected" :options="options"></v-select>
</div>
答案 0 :(得分:1)
我改变了
<script src="https://unpkg.com/vue-select@latest"></script>
到<script src="https://unpkg.com/vue-select@2.4.0/dist/vue-select.js"></script>
。它有效。运行代码,使您知道我在说什么...
Vue.component('v-select', VueSelect.VueSelect)
new Vue({
el: '#app',
data: {
selected:"",
options: [{
id: 1,
label: 'foo'
},
{
id: 3,
label: 'bar'
},
{
id: 2,
label: 'baz'
},
],
}
})
body {
font-family: 'Source Sans Pro', 'Helvetica Neue', Arial, sans-serif;
}
h1 {
font-size: 26px;
font-weight: 600;
color: #2c3e5099;
text-rendering: optimizelegibility;
-moz-osx-font-smoothing: grayscale;
-moz-text-size-adjust: none;
}
#app {
max-width: 30em;
margin: 1em auto;
}
<script src="https://unpkg.com/babel-polyfill@latest/dist/polyfill.min.js"></script>
<script src="https://unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/vue@latest"></script>
<!-- use the latest release -->
<script src="https://unpkg.com/vue-select@2.4.0/dist/vue-select.js"></script>
<div id="app">
<h1>Vue Select - Using v-model</h1>
<v-select multiple v-model="selected" :options="options"></v-select>
</div>
答案 1 :(得分:0)
这是默认行为,因为您在其中放置了多个属性,但不能两次选择foo选项。
如果在选择后坚持删除foo选项,则可以通过观察模型(“ selected”)并检查其值是否已更改来完成,然后从选项中删除foo。另外,如果删除foo,则可以获取模型的先前值(“选定”),将其进行比较,然后将已删除的值放在选项中。
https://vuejs.org/v2/guide/computed.html#Watchers
希望这会对您有所帮助:)