アプリの状態を処理するために、プレゼンテーションを作成し、名前を付け、Vue js と Vuex でスライドを追加/削除できるシンプルなプレゼンテーション ツールを構築しています。すべて順調に進んでいますが、現在、プレゼンテーションの変更 (タイトルの変更またはスライドの追加/削除) を検出する機能を実装しようとしていますが、適切な解決策をまだ見つけることができませんでした. 簡単にするために、タイトルの変更に関する例のみを示します。現在、私の Vuex ストアには次のものがあります。
const state = {
presentations: handover.presentations, //array of objects that comes from the DB
currentPresentation: handover.presentations[0]
}
私のプレゼンテーションコンポーネントには次のものがあります。
export default {
template: '#presentation',
props: ['presentation'],
data: () => {
return {
shadowPresentation: ''
}
},
computed: {
isSelected () {
if (this.getSelectedPresentation !== null) {
return this.presentation === this.getSelectedPresentation
}
return false
},
hasChanged () {
if (this.shadowPresentation.title !== this.presentation.title) {
return true
}
return false
},
...mapGetters(['getSelectedPresentation'])
},
methods: mapActions({
selectPresentation: 'selectPresentation'
}),
created () {
const self = this
self.shadowPresentation = {
title: self.presentation.title,
slides: []
}
self.presentation.slides.forEach(item => {
self.shadowPresentation.slides.push(item)
})
}
}
これまでに行ったことは、コンポーネントの作成時にプレゼンテーションのシャドウ コピーを作成し、計算されたプロパティを使用して、関心のあるプロパティ (この場合はタイトル) を比較し、次の場合に true を返すことです。何もかもが違う。これは変更を検出するために機能しますが、私がやりたいことは、プレゼンテーションが保存されたときにシャドウプレゼンテーションを更新できるようにすることであり、これまでのところ失敗しています。savePresentation アクションが別のコンポーネントでトリガーされ、プレゼンテーション コンポーネント内の「保存」イベントを選択する方法がよくわからないため、シャドウ プレゼンテーションを更新できません。そのような機能をどのように実装できるかについて何か考えはありますか? どんな助けでも大歓迎です!前もって感謝します!