简体   繁体   English

Vuex 模态存储最佳实践

[英]Vuex Modal Store Best Practice

so I'm building a calendar application and the user will be able to edit a booking in the calendar, and the booking editor will be within a modal popup.所以我正在构建一个日历应用程序,用户将能够在日历中编辑预订,并且预订编辑器将位于模式弹出窗口中。

I'm wondering what the best practice would be for the store for this.我想知道商店对此的最佳做法是什么。 Should I create a BookingEditor store and hold the state and methods in there, or should this be part of the Calendar store?我应该创建一个 BookingEditor 存储并在其中保存 state 和方法,还是应该将其作为日历存储的一部分?

I believe it depends on the complexity of the code you're going to write.我相信这取决于您要编写的代码的复杂性。 If it's just a few actions/mutations, I would stick to the calendar store.如果只是一些动作/突变,我会坚持使用日历商店。 Working with multiple modules is great, but people tend to create way too many modules even when there's not an actual reason to使用多个模块很棒,但是即使没有实际理由,人们也倾向于创建太多模块

It's a good practice to separate by concern.按关注点分开是一个很好的做法。 If you need to build a stateful Calendar in your BookingEditor, you could end up with quite some actions and mutations, so having a seperate place to handle those concerns would then be a good idea.如果您需要在您的 BookingEditor 中构建一个有状态的日历,您最终可能会遇到相当多的操作和突变,因此有一个单独的地方来处理这些问题将是一个好主意。

Vuex offers a nice way to create namespaces. Vuex 提供了一种创建命名空间的好方法。 So in your case I would suggest to create a store for your Calendar in a namespace like:因此,在您的情况下,我建议在如下命名空间中为您的日历创建一个商店:

BookingEditor/Calendar

Read more about namespacing in the vuex manual在 vuex 手册中阅读有关命名空间的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM