简体   繁体   English

Vue.js应用程序架构,专注于可重用性和可伸缩性

[英]Vue.js application architecture, focusing on reusability and scalability

I'm working on an Application which is already build for one country. 我正在开发已经为一个国家/地区构建的应用程序。 Now it is required to scale it to multiple countries (20+) with minor changes in each component. 现在需要将其扩展到多个国家(超过20个),每个组成部分都需要进行微小的更改。 How to implement for making code reusable and scalable, ways I thought: 我如何实现使代码可重用和可伸缩的实现:

  • New Repo (Independent releases, no code reuse but easily scalable) 新的回购协议(独立发行版,不重复使用代码,但易于扩展)
  • New Folder for each country, new files only if changes are there (Independent, Little repeated code, Looks scalable ) 每个国家/地区的新文件夹,仅在有更改的情况下才有新文件(独立,重复代码很少,看起来可扩展)
  • Using v-if on divs to decide to show or not (Dependent releases, Highly reusable, but difficult scalability making code dirty) 在div上使用v-if决定显示还是不显示(依赖版本,高度可重用,但难于扩展,使代码变脏)

App structure/Code: There is a form whose fields and validations will change based on country. 应用程序结构/代码:存在一种表格,其字段和验证将根据国家/地区而变化。 Plus few banners whose banner layout is based on country. 加上少量横幅,其横幅布局基于国家/地区。

Would like to know how we can architect such Vue.js Application ? 想知道我们如何构建这样的Vue.js应用程序?

很难看到所有代码,但是如果您已经在使用i18n更改语言字符串并且所做的更改确实很小,我认为v-if是您的最佳选择。

Instead of having v-ifs, I'd delegate this logic to a custom component: 我没有使用v-if,而是将此逻辑委托给自定义组件:

Instead of: 代替:

<h2>Country Specific</h2>
<v-if="country=='A'>
<v-if="country=='B'>
<v-if="country=='C'>
etc...

Do this: 做这个:

<h2>Country Specific</h2>
<custom-module country="currentCountry"/>

and group all these "per country" modules under a specific folder separate from your "global/shared" system. 并将所有这些“按国家/地区”模块分组到与“全球/共享”系统分开的特定文件夹下。

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

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