同じインスタンスに対して新しい属性を作成するときのオブジェクトのデフォルト動作は、プロパティを変更して古いものを参照するということです。だから、私は段落の変更の内側にボタンをデータをクリックしvuejsを使ってオブジェクトを参照しないようにします
export default {
data() {
return {
paragraph: {
text: "",
fontSize: 14,
key: "Paragraph",
align: "left"
}
}
},
methods: {
addParagraph() {
this.$set(this.paragraph, 'key', this.paragraph.key);
this.$set(this.paragraph, 'text', this.paragraph.text);
this.$set(this.paragraph, 'fontSize', this.paragraph.fontSize);
this.$set(this.paragraph, 'align', this.paragraph.align);
this.$store.commit("appendToDocument", this.paragraph)
},
alignment(option) {
this.paragraph.align = option;
}
}
毎回、私はJSONに追加するストアをvuexするデータをPASたい:
私はVUEデータ上でこのような何かを持っています私はパラグラフの木を持つことができます、問題は、そのeverttime私は前に作成した私の他の段落の値を変更する新しいパラグラップを作成する、それを変更する方法はありますか?
どういう意味ですか? –
ここで良い例が見つかりますhttps://github.com/tc39/proposal-object-rest-spread/blob/master/Spread.md この場合、3ドット演算子は意味します: 新しいオブジェクトを作成し、すべてをコピーします。オブジェクトBのプロパティを貼り付けてペーストし、オブジェクトAに追加します。 基本的には、{... this.paragraph}では、どのような@potrayコードを行うのですか? 配列のスプレッド/レスト演算子に慣れているかもしれません。それはES2015に上陸しました。 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator。 オブジェクトのスプレッド/レットはほとんど標準です –
ちょっと考えてください、何が参考になるのですか、IDは気にしませんか? D –