【发布时间】:2017-11-26 00:43:21
【问题描述】:
我有一个 vue-select 多选 (http://sagalbot.github.io/vue-select/) 定义为
<v-Select label="label" multiple :on-change="updateCities" :options="cities"></v-Select>
方法updateCities定义为
'updateCities': function (menuItem) {
var name = ''
// iterate thru the elements in the multiselect
menuItem.forEach(function (elem, i) {
name = elem.label
return name
})
// push the selected element to an array in the data model
this.state.city.push(name)
}
数据模型定义为
'data' () {
return {
'state': {
'city': []
}
}
}
当我单击多选并选择一个城市时,菜单和数据模型数组city 都会正确更新,但是当我单击菜单项右上角的 X 以从菜单中删除元素时来自数据模型数组city。如下所示
该元素已从菜单中正确删除,但未从数据模型数组 city 中删除。
我该如何解决这个问题?
【问题讨论】:
-
你能用小提琴/codepen 来演示这个问题吗?
-
你应该在推送之前清除
this.state.city吗?我说不出来。请注意,forEach中的return是没有意义的。
标签: javascript vue.js vuejs2