【发布时间】:2023-03-03 01:33:02
【问题描述】:
我有以下代码:
var CatShelter = {
template:
'<vue-multiselect' +
' :options="options">' +
'<template> <i v-on:click="removeCats(option)"></i></span> </template>' +
'</vue-multiselect>' +,
props: {options: Array},
methods: {
removeCats: function (object) {
self = this;
this.options.pop();
$.ajax({
type: "PATCH",
url: //irrelevant,
'data': //irrelveant,
'dataType': 'json',
success: function (result) {
},
error: function (result) {
}
});
}
}
}
},
基本上,当单击图标时,它会调用此 ajax 请求,该请求会通过 DB 从 vue 多选中删除一个选项。这工作正常。当我刷新时,会发生变化。我希望能够实时删除选项。 options 属性本质上是一个对象数组。如何让 vue 更新道具而不刷新调整 vue 多选?
**更新**
这是我真正的多选与您实施的更改。
'<vue-multiselect' +
' :options.sync="options"' +
'<template slot="tag" slot-scope="{ option }"><span class="multiselect__tag"><span><img class="option__image" :src="option.img" width="16px" style="color: #ffffff;" /></span> [[ option.displayName ]] <i aria-hidden="true" tabindex="1" class="multiselect__tag-icon" v-on:click="removeTagAndRelevantTeamMembers(option)"></i></span> </template>' +
'<template slot="option" slot-scope="{ option }">\n' +
' <img class="option__image" :src="option.img" width="16px" />\n' +
' <span class="option__desc">\n' +
' <span class="option__title">[[ option.displayName ]]</span>\n' +
' </span>\n' +
' </template>' +
'</vue-multiselect>' +
这是我真正实现的 js:
var me = this;
$.ajax({
type: "PATCH",
url: //irrelv,
'data': //irrelv,
'dataType': 'json',
success: function (result) {
me.$emit('update:options', updated);
},
error: function (result) {
}
});
【问题讨论】:
标签: javascript vue.js frontend vue-component vue-props