Vue.component("values-box", { props: ["values", "size", "maxlength", "name", "placeholder"], data: function () { let values = this.values; if (values == null) { values = []; } return { "vValues": 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.vValues[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.vValues, this.index, this.value); } else { this.vValues.push(this.value); } this.cancel() this.$emit("change", this.vValues) }, remove: function (index) { this.vValues.$remove(index) this.$emit("change", this.vValues) }, cancel: function () { this.isUpdating = false; this.isAdding = false; this.value = ""; }, updateAll: function (values) { this.vValeus = values }, addValue: function (v) { this.vValues.push(v) }, startEditing: function () { this.isEditing = !this.isEditing } }, template: `
{{value}}
[修改]
{{value}}  
` });