From 654f340a376e71f8cde2032cf08238144943a724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=88=90?= Date: Wed, 8 Oct 2025 16:12:13 +0800 Subject: [PATCH] 1 --- 完整使用文档.md | 90 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/完整使用文档.md b/完整使用文档.md index 895e228..68850d6 100644 --- a/完整使用文档.md +++ b/完整使用文档.md @@ -782,6 +782,96 @@ A: **框架已包含所有系统功能,只需准备:** 其他所有系统页面、API、组件都已在框架中,无需复制! +### Q9: `this.$store.dispatch` 报错怎么办? + +A: **常见原因和解决方案**: + +**1. Store 未正确挂载** + +确保在创建 Vue 实例时使用了框架的 store: +```javascript +new Vue({ + el: '#app', + router: AdminFramework.router, + store: AdminFramework.store, // ✅ 必须挂载 store + render: h => h(App) +}) +``` + +**2. 命名空间路径错误** + +框架的 store 模块都使用了 `namespaced: true`,必须带上模块名: +```javascript +// ❌ 错误 - 缺少命名空间 +this.$store.dispatch('setAuthorityMenus', data) + +// ✅ 正确 - 带上模块名 user/ +this.$store.dispatch('user/setAuthorityMenus', data) + +// ✅ 正确 - app 模块 +this.$store.dispatch('app/getSysTitle', { defaultTitle: '系统' }) +``` + +**3. Store 在 setup/install 时未创建** + +确保在 Vue.use() 时传入了 Vuex: +```javascript +// ✅ 正确 - 框架会自动创建 store +Vue.use(AdminFramework, { + config, + ViewUI, + VueRouter, + Vuex, // ✅ 必须传入 Vuex + createPersistedState +}) +``` + +**4. 可用的 Store Actions** + +**user 模块**(需要加 `user/` 前缀): +- `user/setAuthorityMenus` - 设置权限菜单 +- `user/handleLogin` - 处理登录 +- `user/handleLogOut` - 处理登出 + +**app 模块**(需要加 `app/` 前缀): +- `app/getSysTitle` - 获取系统标题和 Logo + +**完整示例**: +```javascript +export default { + mounted() { + // 设置权限菜单 + this.$store.dispatch('user/setAuthorityMenus', { + Main: AdminFramework.Main, + ParentView: AdminFramework.ParentView, + Page404: AdminFramework.Page404 + }) + + // 获取系统标题 + this.$store.dispatch('app/getSysTitle', { + defaultTitle: '智能代码平台', + defaultLogo: '' + }) + }, + methods: { + async login() { + // 处理登录 + await this.$store.dispatch('user/handleLogin', { + userFrom: { username: 'admin', password: '123456' }, + Main: AdminFramework.Main, + ParentView: AdminFramework.ParentView, + Page404: AdminFramework.Page404 + }) + this.$router.push({ name: 'home' }) + }, + logout() { + // 处理登出 + this.$store.dispatch('user/handleLogOut') + } + } +} +``` + --- ## 📦 完整的项目结构示例