Vue.component("values-box", { props: ["values", "v-values", "size", "maxlength", "name", "placeholder"], data: function () { let values = this.values; if (values == null) { values = []; } if (this.vValues != null && typeof this.vValues == "object") { values = this.vValues } return { "realValues": values, "isUpdating": false, "isAdding": false, "index": 0, "value": "", isEditing: false } }, methods: { create: function () { this.isAdding = true; var that = this; setTimeout(function () { that.$refs.value.focus(); }, 200); }, update: function (index) { this.cancel() this.isUpdating = true; this.index = index; this.value = this.realValues[index]; var that = this; setTimeout(function () { that.$refs.value.focus(); }, 200); }, confirm: function () { if (this.value.length == 0) { return } if (this.isUpdating) { Vue.set(this.realValues, this.index, this.value); } else { this.realValues.push(this.value); } this.cancel() this.$emit("change", this.realValues) }, remove: function (index) { this.realValues.$remove(index) this.$emit("change", this.realValues) }, cancel: function () { this.isUpdating = false; this.isAdding = false; this.value = ""; }, updateAll: function (values) { this.realValues = values }, addValue: function (v) { this.realValues.push(v) }, startEditing: function () { this.isEditing = !this.isEditing }, allValues: function () { return this.realValues } }, template: `
{{value}}
[修改]
{{value}}  
` });