phoenix

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Phoenix

Phoenix

Phoenix (Elixir) provides real-time scalability (millions of connections). v1.7 + LiveView allows building rich SPAs without writing JavaScript.
Phoenix(Elixir)提供实时可扩展性(支持数百万连接)。v1.7版本搭配LiveView,无需编写JavaScript即可构建丰富的单页应用(SPA)。

When to Use

适用场景

  • Real-time: Chat apps, live dashboards (Channels).
  • High Concurrency: Leveraging the BEAM VM (Erlang).
  • Low JS: LiveView handles the UI state on the server.
  • 实时场景:聊天应用、实时仪表盘(借助Channels)。
  • 高并发场景:依托BEAM虚拟机(Erlang)实现。
  • 少JavaScript需求:LiveView在服务器端处理UI状态。

Core Concepts

核心概念

LiveView

LiveView

Server-rendered HTML that updates over WebSockets. "The server is the state source".
通过WebSocket更新的服务器渲染HTML。“服务器是状态源”。

Ecto

Ecto

The database wrapper. Using
Changeset
for validation.
数据库封装层,使用
Changeset
进行验证。

PubSub

PubSub

Built-in, distributed publish-subscribe system.
内置的分布式发布-订阅系统。

Best Practices (2025)

2025年最佳实践

Do:
  • Use Verified Routes:
    ~p"/users/#{@user}"
    ensures compile-time link safety.
  • Use Tailwind: Default in 1.7.
  • Use Function Components: HEEx templates with declarative assigns.
Don't:
  • Don't use SPA unless needed: LiveView covers 95% of use cases.
推荐做法
  • 使用Verified Routes
    ~p"/users/#{@user}"
    确保编译时链接安全性。
  • 使用Tailwind:1.7版本默认集成。
  • 使用函数式组件:采用HEEx模板和声明式赋值。
不推荐做法
  • 非必要不使用SPA:LiveView可覆盖95%的使用场景。

References

参考资料