You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

registerModule中子模块名称允许字符范围及子模块键规则咨询

关于registerModule子模块键的允许字符范围

Great question — it’s totally fair to wonder about these unwritten (or hard-to-find) naming rules! Let’s start with the most common context for registerModule(): Vuex, Vue’s state management library.

First, a quick correction on parameters: in Vuex’s registerModule(), the module key (or path) is actually the first argument (either a string like 'checkout' or an array like ['admin', 'dashboard']), while the third argument is optional configuration (like preserveState). But regardless of the parameter position, the naming rules for the module key itself are consistent:

  • The official docs don’t list strict, explicit character limits, but you’ll want to avoid spaces and special characters like !@#$%^&*() entirely. These can cause issues with path parsing, debugging tools, or even unexpected behavior when accessing module state.
  • Recommended characters to stick with:
    • Uppercase and lowercase letters (A-Z, a-z)
    • Numbers (0-9) — though it’s best not to start a key with a number, since that conflicts with JavaScript’s identifier rules (module keys become properties on the state tree, after all)
    • Underscores (_) and hyphens (-) — hyphens work but require bracket notation to access (e.g., $store.state['user-settings']), so underscores are more convenient for snake_case naming, or you can use camelCase like userSettings

In practice, following JavaScript’s identifier naming conventions (with the exception of hyphens if you don’t mind bracket notation) is a safe bet. This ensures your module keys play nicely with the framework’s internal logic and are easy for other developers to read and work with.

Examples of good keys: user_profile, productCatalog, order_789
Examples of keys to avoid: user settings (spaces), admin@panel (special symbols), 123_cart (starts with number)

If you’re using a different framework or custom registerModule() function, the rules might shift slightly, but the core principle stays the same: keep names clean, free of ambiguous characters, and compatible with how the framework parses or references module keys.


内容的提问来源于stack exchange,提问作者Sybille Peters

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:58:52