{"id":100744,"date":"2026-09-05T08:01:03","date_gmt":"2026-09-05T00:01:03","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/100744.html"},"modified":"2026-09-05T08:01:03","modified_gmt":"2026-09-05T00:01:03","slug":"%e7%ac%ac%e5%8d%81%e5%9b%9b%e8%8a%82%ef%bc%9a%e5%90%8e%e7%ab%af%e8%bf%94%e5%9b%9e%e6%9d%83%e9%99%90%e5%8a%a8%e6%80%81%e8%b7%af%e7%94%b1","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/100744.html","title":{"rendered":"\u7b2c\u5341\u56db\u8282\uff1a\u540e\u7aef\u8fd4\u56de\u6743\u9650\u52a8\u6001\u8def\u7531"},"content":{"rendered":"<h2>\u7b2c\u5341\u56db\u8282&#xff1a;\u540e\u7aef\u8fd4\u56de\u6743\u9650\u52a8\u6001\u8def\u7531<\/h2>\n<p>\u76ee\u6807&#xff1a;\u767b\u5f55\u540e\u4ece\u540e\u7aef&#xff08;mock&#xff09;\u83b7\u53d6\u8be5\u7528\u6237\u53ef\u8bbf\u95ee\u7684\u83dc\u5355\u8def\u7531&#xff0c;\u52a8\u6001\u6ce8\u518c\u5230\u8def\u7531\u7cfb\u7edf&#xff0c;\u4fa7\u8fb9\u680f\u83dc\u5355\u6839\u636e\u8fd4\u56de\u7684\u8def\u7531\u81ea\u52a8\u6e32\u67d3\u3002\u4e0d\u540c\u89d2\u8272\u8fd4\u56de\u4e0d\u540c\u8def\u7531&#xff0c;\u5b9e\u73b0\u6743\u9650\u63a7\u5236\u3002<\/p>\n<h3>\u4e00\u3001\u5148\u641e\u61c2\u539f\u7406&#xff08;\u975e\u5e38\u91cd\u8981&#xff09;<\/h3>\n<p>\u4f20\u7edf\u5199\u6b7b\u8def\u7531\u7684\u65b9\u5f0f&#xff1a;<\/p>\n<p>router\/index.js \u91cc\u5199\u6b7b\u6240\u6709\u8def\u7531 \u2192 \u9879\u76ee\u542f\u52a8\u5c31\u5168\u90e8\u6ce8\u518c \u2192 \u6240\u6709\u4eba\u90fd\u80fd\u8bbf\u95ee\u6240\u6709\u9875\u9762<\/p>\n<p>\u52a8\u6001\u8def\u7531\u7684\u65b9\u5f0f&#xff1a;<\/p>\n<p>router\/index.js \u53ea\u5199\u767b\u5f55\u3001404\u7b49\u5e38\u91cf\u8def\u7531<br \/>\n    \u2193<br \/>\n\u7528\u6237\u767b\u5f55\u62ff\u5230 token<br \/>\n    \u2193<br \/>\n\u8df3\u8f6c\u9996\u9875 \u2192 \u89e6\u53d1\u8def\u7531\u5b88\u536b<br \/>\n    \u2193<br \/>\n\u5b88\u536b\u53d1\u73b0\u8fd8\u6ca1\u52a0\u8f7d\u7528\u6237\u4fe1\u606f \u2192 \u8c03\u7528 \/getUserInfo \u63a5\u53e3<br \/>\n    \u2193<br \/>\n\u540e\u7aef\u8fd4\u56de routes \u6570\u7ec4&#xff08;component \u662f\u5b57\u7b26\u4e32&#xff0c;\u5982 &#034;dashboard\/index&#034;&#xff09;<br \/>\n    \u2193<br \/>\n\u5de5\u5177\u51fd\u6570 filterAsyncRoutes \u628a\u5b57\u7b26\u4e32\u8f6c\u6210\u771f\u5b9e Vue \u7ec4\u4ef6<br \/>\n    \u2193<br \/>\nrouter.addRoute() \u4e00\u6761\u6761\u6ce8\u518c\u52a8\u6001\u8def\u7531<br \/>\n    \u2193<br \/>\n\u91cd\u65b0\u89e6\u53d1\u5bfc\u822a \u2192 \u9875\u9762\u6b63\u5e38\u663e\u793a<br \/>\n    \u2193<br \/>\n\u4fa7\u8fb9\u680f\u8bfb\u53d6 store \u91cc\u7684\u8def\u7531\u6570\u7ec4 \u2192 \u81ea\u52a8\u6e32\u67d3\u83dc\u5355<\/p>\n<p>\u6838\u5fc3\u5751\u70b9\u63d0\u524d\u8bf4&#xff1a;<\/p>\n<li>router.addRoute() \u662f\u8fd0\u884c\u65f6\u6dfb\u52a0&#xff0c;\u6dfb\u52a0\u5b8c\u5fc5\u987b\u91cd\u65b0\u5bfc\u822a\u4e00\u6b21\u624d\u751f\u6548<\/li>\n<li>404 \u901a\u914d\u8def\u7531\u5fc5\u987b\u6700\u540e\u6ce8\u518c&#xff0c;\u5426\u5219\u4f1a\u62e6\u622a\u6240\u6709\u52a8\u6001\u8def\u7531<\/li>\n<li>\u540e\u7aef\u8fd4\u56de\u7684 component \u662f\u5b57\u7b26\u4e32&#xff0c;\u5fc5\u987b\u7528\u5de5\u5177\u51fd\u6570\u8f6c\u6210\u771f\u5b9e\u7ec4\u4ef6<\/li>\n<li>Layout \u7ec4\u4ef6\u8981\u7528 markRaw \u6807\u8bb0&#xff0c;\u9632\u6b62\u88ab Pinia \u53d8\u6210\u54cd\u5e94\u5f0f<\/li>\n<li>\u767b\u5f55\u9875\u9762\u4e0d\u8981\u624b\u52a8\u8c03\u7528 getUserInfo&#xff0c;\u5168\u90e8\u4ea4\u7ed9\u8def\u7531\u5b88\u536b<\/li>\n<hr \/>\n<h3>\u4e8c\u3001\u5b8c\u6574\u6587\u4ef6\u4ee3\u7801&#xff08;\u76f4\u63a5\u590d\u5236\u7c98\u8d34&#xff09;<\/h3>\n<h4>\u6587\u4ef6 1&#xff1a;src\/mock\/index.js&#xff08;\u6a21\u62df\u540e\u7aef\u63a5\u53e3&#xff09;<\/h4>\n<p>export default {<br \/>\n  \/\/ \u767b\u5f55\u63a5\u53e3<br \/>\n  &#039;\/login&#039;: (params) &#061;&gt; {<br \/>\n    const { username, password } &#061; params<br \/>\n    if (username &#061;&#061;&#061; &#039;admin&#039; &amp;&amp; password &#061;&#061;&#061; &#039;123456&#039;) {<br \/>\n      return {<br \/>\n        code: 200,<br \/>\n        msg: &#039;\u767b\u5f55\u6210\u529f&#039;,<br \/>\n        data: {<br \/>\n          token: &#039;mock-token-123456&#039; \/\/ \u5fc5\u987b\u8fd4\u56de token&#xff01;<br \/>\n        }<br \/>\n      }<br \/>\n    } else {<br \/>\n      return {<br \/>\n        code: 500,<br \/>\n        msg: &#039;\u8d26\u53f7\u5bc6\u7801\u9519\u8bef&#039;,<br \/>\n        data: null<br \/>\n      }<br \/>\n    }<br \/>\n  },<\/p>\n<p>  \/\/ \u83b7\u53d6\u7528\u6237\u4fe1\u606f &#043; \u52a8\u6001\u83dc\u5355\u8def\u7531<br \/>\n  &#039;\/getUserInfo&#039;: () &#061;&gt; {<br \/>\n    return {<br \/>\n      code: 200,<br \/>\n      msg: &#039;\u83b7\u53d6\u6210\u529f&#039;,<br \/>\n      data: {<br \/>\n        username: &#039;admin&#039;,<br \/>\n        roles: [&#039;admin&#039;],<br \/>\n        \/\/ \u540e\u7aef\u8fd4\u56de\u7684\u8def\u7531&#xff0c;component \u5168\u90e8\u662f\u5b57\u7b26\u4e32<br \/>\n        routes: [<br \/>\n          {<br \/>\n            path: &#039;\/dashboard&#039;,<br \/>\n            component: &#039;Layout&#039;,<br \/>\n            meta: { title: &#039;\u9996\u9875&#039;, icon: &#039;House&#039; },<br \/>\n            children: [<br \/>\n              {<br \/>\n                path: &#039;index&#039;,<br \/>\n                component: &#039;dashboard\/index&#039;,<br \/>\n                meta: { title: &#039;\u5de5\u4f5c\u53f0&#039; }<br \/>\n              }<br \/>\n            ]<br \/>\n          },<br \/>\n          {<br \/>\n            path: &#039;\/system&#039;,<br \/>\n            component: &#039;Layout&#039;,<br \/>\n            meta: { title: &#039;\u7cfb\u7edf\u7ba1\u7406&#039;, icon: &#039;Setting&#039; },<br \/>\n            children: [<br \/>\n              {<br \/>\n                path: &#039;user&#039;,<br \/>\n                component: &#039;system\/user\/index&#039;,<br \/>\n                meta: { title: &#039;\u7528\u6237\u7ba1\u7406&#039; }<br \/>\n              }<br \/>\n            ]<br \/>\n          }<br \/>\n        ]<br \/>\n      }<br \/>\n    }<br \/>\n  }<br \/>\n}<\/p>\n<p>\u4ee5\u540e\u65b0\u589e\u9875\u9762&#xff0c;\u4e0d\u8981\u5728 router\/index.js \u91cc\u52a0\u8def\u7531&#xff0c;\u76f4\u63a5\u5728\u8fd9\u91cc\u7684 routes \u6570\u7ec4\u91cc\u52a0\u914d\u7f6e\u3002<\/p>\n<hr \/>\n<h4>\u6587\u4ef6 2&#xff1a;src\/utils\/filterAsyncRoutes.js&#xff08;\u8def\u7531\u8f6c\u6362\u5de5\u5177&#xff09;<\/h4>\n<p>import { markRaw } from &#039;vue&#039;<br \/>\n\/\/ Vite \u6279\u91cf\u8bfb\u53d6 views \u4e0b\u6240\u6709 vue \u6587\u4ef6<br \/>\nconst viewsModules &#061; import.meta.glob(&#039;&#064;\/views\/**\/*.vue&#039;)<br \/>\n\/\/ \u5f15\u5165 Layout \u5e03\u5c40\u7ec4\u4ef6<br \/>\nimport Layout from &#039;&#064;\/layout\/index.vue&#039;<\/p>\n<p>\/**<br \/>\n * \u628a\u540e\u7aef\u8fd4\u56de\u7684\u5b57\u7b26\u4e32\u8def\u7531&#xff0c;\u8f6c\u6362\u6210 Vue Router \u53ef\u7528\u7684\u8def\u7531\u5bf9\u8c61<br \/>\n * &#064;param {Array} backRoutes \u540e\u7aef\u8fd4\u56de\u7684\u8def\u7531\u6570\u7ec4<br \/>\n * &#064;returns \u8f6c\u6362\u5b8c\u6210\u7684\u8def\u7531\u6570\u7ec4<br \/>\n *\/<br \/>\nexport function filterAsyncRoutes(backRoutes) {<br \/>\n  const res &#061; []<\/p>\n<p>  backRoutes.forEach((item) &#061;&gt; {<br \/>\n    const route &#061; { &#8230;item }<\/p>\n<p>    \/\/ Layout \u7279\u6b8a\u5904\u7406&#xff0c;\u7528 markRaw \u9632\u6b62\u88ab\u53d8\u6210\u54cd\u5e94\u5f0f<br \/>\n    if (route.component &#061;&#061;&#061; &#039;Layout&#039;) {<br \/>\n      route.component &#061; markRaw(Layout)<br \/>\n    } else {<br \/>\n      \/\/ \u666e\u901a\u9875\u9762&#xff0c;\u62fc\u63a5\u8def\u5f84\u5339\u914d glob \u5bfc\u5165\u7684\u6a21\u5757<br \/>\n      const filePath &#061; &#096;\/src\/views\/${route.component}.vue&#096;<br \/>\n      route.component &#061; viewsModules[filePath]<br \/>\n    }<\/p>\n<p>    \/\/ \u9012\u5f52\u5904\u7406\u5b50\u8def\u7531<br \/>\n    if (route.children &amp;&amp; route.children.length &gt; 0) {<br \/>\n      route.children &#061; filterAsyncRoutes(route.children)<br \/>\n    }<\/p>\n<p>    res.push(route)<br \/>\n  })<\/p>\n<p>  return res<br \/>\n}<\/p>\n<hr \/>\n<h4>\u6587\u4ef6 3&#xff1a;src\/stores\/user.js&#xff08;Pinia \u7528\u6237\u4ed3\u5e93&#xff09;<\/h4>\n<p>import { defineStore } from &#039;pinia&#039;<br \/>\nimport { loginApi, getUserInfoApi } from &#039;&#064;\/api\/login&#039;<br \/>\nimport { filterAsyncRoutes } from &#039;&#064;\/utils\/filterAsyncRoutes&#039;<\/p>\n<p>export const useUserStore &#061; defineStore(&#039;user&#039;, {<br \/>\n  state: () &#061;&gt; ({<br \/>\n    token: localStorage.getItem(&#039;token&#039;) || &#039;&#039;,<br \/>\n    username: &#039;&#039;,<br \/>\n    roles: [],<br \/>\n    addRoutes: [] \/\/ \u5b58\u653e\u8f6c\u6362\u5b8c\u6210\u7684\u52a8\u6001\u8def\u7531<br \/>\n  }),<\/p>\n<p>  actions: {<br \/>\n    \/\/ \u767b\u5f55&#xff1a;\u53ea\u62ff token<br \/>\n    async login(form) {<br \/>\n      const res &#061; await loginApi(form)<br \/>\n      if (res.code &#061;&#061;&#061; 200) {<br \/>\n        if (!res.data?.token) {<br \/>\n          throw new Error(&#039;\u63a5\u53e3\u672a\u8fd4\u56de token&#039;)<br \/>\n        }<br \/>\n        this.token &#061; res.data.token<br \/>\n        localStorage.setItem(&#039;token&#039;, this.token)<br \/>\n      } else {<br \/>\n        throw new Error(res.msg || &#039;\u767b\u5f55\u5931\u8d25&#039;)<br \/>\n      }<br \/>\n    },<\/p>\n<p>    \/\/ \u83b7\u53d6\u7528\u6237\u4fe1\u606f &#043; \u8f6c\u6362\u52a8\u6001\u8def\u7531<br \/>\n    async getUserInfo() {<br \/>\n      const res &#061; await getUserInfoApi()<br \/>\n      if (res.code &#061;&#061;&#061; 200) {<br \/>\n        this.username &#061; res.data.username<br \/>\n        this.roles &#061; res.data.roles<br \/>\n        \/\/ \u8c03\u7528\u5de5\u5177\u51fd\u6570&#xff0c;\u628a\u540e\u7aef\u5b57\u7b26\u4e32\u8def\u7531\u8f6c\u6210\u7ec4\u4ef6\u8def\u7531<br \/>\n        this.addRoutes &#061; filterAsyncRoutes(res.data.routes)<br \/>\n        return this.addRoutes<br \/>\n      }<br \/>\n      throw new Error(&#039;\u83b7\u53d6\u7528\u6237\u4fe1\u606f\u5931\u8d25&#039;)<br \/>\n    },<\/p>\n<p>    \/\/ \u9000\u51fa\u767b\u5f55<br \/>\n    logout() {<br \/>\n      this.token &#061; &#039;&#039;<br \/>\n      this.username &#061; &#039;&#039;<br \/>\n      this.roles &#061; []<br \/>\n      this.addRoutes &#061; []<br \/>\n      localStorage.removeItem(&#039;token&#039;)<br \/>\n    }<br \/>\n  }<br \/>\n})<\/p>\n<hr \/>\n<h4>\u6587\u4ef6 4&#xff1a;src\/router\/index.js&#xff08;\u8def\u7531\u914d\u7f6e &#043; \u5b88\u536b&#xff09;<\/h4>\n<p>import { createRouter, createWebHistory } from &#039;vue-router&#039;<br \/>\nimport { useUserStore } from &#039;&#064;\/stores\/user&#039;<br \/>\nimport { useTagsViewStore } from &#039;&#064;\/stores\/tagsView&#039;<\/p>\n<p>\/\/ \u5e38\u91cf\u8def\u7531&#xff1a;\u6240\u6709\u4eba\u90fd\u80fd\u8bbf\u95ee&#xff0c;\u9879\u76ee\u542f\u52a8\u5c31\u6ce8\u518c<br \/>\nexport const constantRoutes &#061; [<br \/>\n  { path: &#039;\/&#039;, redirect: &#039;\/login&#039; },<br \/>\n  { path: &#039;\/login&#039;, component: () &#061;&gt; import(&#039;&#064;\/views\/login\/index.vue&#039;) },<br \/>\n  { path: &#039;\/401&#039;, component: () &#061;&gt; import(&#039;&#064;\/views\/error\/401.vue&#039;) },<br \/>\n  { path: &#039;\/404&#039;, component: () &#061;&gt; import(&#039;&#064;\/views\/error\/404.vue&#039;) },<br \/>\n  { path: &#039;\/500&#039;, component: () &#061;&gt; import(&#039;&#064;\/views\/error\/500.vue&#039;) }<br \/>\n]<\/p>\n<p>const router &#061; createRouter({<br \/>\n  history: createWebHistory(import.meta.env.BASE_URL),<br \/>\n  routes: [&#8230;constantRoutes]<br \/>\n})<\/p>\n<p>\/\/ \u5168\u5c40\u524d\u7f6e\u5b88\u536b&#xff1a;\u6743\u9650\u63a7\u5236\u6838\u5fc3<br \/>\nrouter.beforeEach(async (to, from) &#061;&gt; {<br \/>\n  const userStore &#061; useUserStore()<br \/>\n  \/\/ \u767d\u540d\u5355&#xff1a;\u4e0d\u9700\u8981\u767b\u5f55\u5c31\u80fd\u8bbf\u95ee<br \/>\n  const whiteList &#061; [&#039;\/login&#039;, &#039;\/404&#039;, &#039;\/401&#039;, &#039;\/500&#039;]<\/p>\n<p>  if (userStore.token) {<br \/>\n    \/\/ \u6709 token&#xff0c;\u8bbf\u95ee\u767b\u5f55\u9875 \u2192 \u8df3\u9996\u9875<br \/>\n    if (to.path &#061;&#061;&#061; &#039;\/login&#039;) {<br \/>\n      return &#039;\/dashboard\/index&#039;<br \/>\n    }<\/p>\n<p>    \/\/ roles \u4e3a\u7a7a &#061; \u8fd8\u6ca1\u52a0\u8f7d\u7528\u6237\u4fe1\u606f&#xff08;\u521a\u767b\u5f55 \/ \u5237\u65b0\u9875\u9762&#xff09;<br \/>\n    if (userStore.roles.length &#061;&#061;&#061; 0) {<br \/>\n      try {<br \/>\n        \/\/ 1. \u83b7\u53d6\u7528\u6237\u4fe1\u606f&#xff0c;\u62ff\u5230\u8f6c\u6362\u5b8c\u6210\u7684\u52a8\u6001\u8def\u7531<br \/>\n        const accessRoutes &#061; await userStore.getUserInfo()<\/p>\n<p>        \/\/ 2. \u5faa\u73af\u6ce8\u518c\u52a8\u6001\u8def\u7531<br \/>\n        accessRoutes.forEach((route) &#061;&gt; {<br \/>\n          router.addRoute(route)<br \/>\n        })<\/p>\n<p>        \/\/ 3. \u6700\u540e\u6ce8\u518c 404 \u901a\u914d\u8def\u7531&#xff08;\u5fc5\u987b\u5728\u6240\u6709\u4e1a\u52a1\u8def\u7531\u4e4b\u540e&#xff01;&#xff09;<br \/>\n        router.addRoute({<br \/>\n          path: &#039;\/:pathMatch(.*)*&#039;,<br \/>\n          redirect: &#039;\/404&#039;<br \/>\n        })<\/p>\n<p>        \/\/ 4. \u91cd\u65b0\u89e6\u53d1\u5bfc\u822a&#xff0c;\u8ba9\u521a\u521a addRoute \u7684\u8def\u7531\u751f\u6548<br \/>\n        return { &#8230;to, replace: true }<br \/>\n      } catch (err) {<br \/>\n        console.error(&#039;\u52a0\u8f7d\u52a8\u6001\u8def\u7531\u5931\u8d25&#xff1a;&#039;, err)<br \/>\n        userStore.logout()<br \/>\n        return &#039;\/login&#039;<br \/>\n      }<br \/>\n    }<\/p>\n<p>    \/\/ \u5df2\u7ecf\u52a0\u8f7d\u8fc7\u7528\u6237\u4fe1\u606f&#xff0c;\u76f4\u63a5\u653e\u884c<br \/>\n    return true<br \/>\n  } else {<br \/>\n    \/\/ \u6ca1\u6709 token<br \/>\n    if (whiteList.includes(to.path)) {<br \/>\n      return true<br \/>\n    } else {<br \/>\n      return &#039;\/login&#039;<br \/>\n    }<br \/>\n  }<br \/>\n})<\/p>\n<p>\/\/ \u5168\u5c40\u540e\u7f6e\u5b88\u536b&#xff1a;\u5904\u7406\u6807\u7b7e\u9875<br \/>\nrouter.afterEach((to) &#061;&gt; {<br \/>\n  const tagsViewStore &#061; useTagsViewStore()<br \/>\n  if (to.meta.title) {<br \/>\n    tagsViewStore.addView(to)<br \/>\n  }<br \/>\n})<\/p>\n<p>export default router<\/p>\n<hr \/>\n<h4>\u6587\u4ef6 5&#xff1a;src\/views\/login\/index.vue&#xff08;\u767b\u5f55\u9875\u9762&#xff09;<\/h4>\n<p>&lt;template&gt;<br \/>\n  &lt;div class&#061;&#034;login-container&#034;&gt;<br \/>\n    &lt;el-card style&#061;&#034;width: 420px; margin: 100px auto;&#034;&gt;<br \/>\n      &lt;h2 style&#061;&#034;text-align: center; margin-bottom: 20px;&#034;&gt;\u7cfb\u7edf\u767b\u5f55&lt;\/h2&gt;<br \/>\n      &lt;el-form&gt;<br \/>\n        &lt;el-form-item label&#061;&#034;\u8d26\u53f7&#034;&gt;<br \/>\n          &lt;el-input v-model&#061;&#034;loginForm.username&#034;&gt;&lt;\/el-input&gt;<br \/>\n        &lt;\/el-form-item&gt;<br \/>\n        &lt;el-form-item label&#061;&#034;\u5bc6\u7801&#034;&gt;<br \/>\n          &lt;el-input v-model&#061;&#034;loginForm.password&#034; type&#061;&#034;password&#034;&gt;&lt;\/el-input&gt;<br \/>\n        &lt;\/el-form-item&gt;<br \/>\n        &lt;el-button type&#061;&#034;primary&#034; style&#061;&#034;width: 100%&#034; &#064;click&#061;&#034;handleLogin&#034;&gt;<br \/>\n          \u767b\u5f55<br \/>\n        &lt;\/el-button&gt;<br \/>\n      &lt;\/el-form&gt;<br \/>\n    &lt;\/el-card&gt;<br \/>\n  &lt;\/div&gt;<br \/>\n&lt;\/template&gt;<\/p>\n<p>&lt;script setup&gt;<br \/>\nimport { reactive } from &#039;vue&#039;<br \/>\nimport { useUserStore } from &#039;&#064;\/stores\/user&#039;<br \/>\nimport { useRouter } from &#039;vue-router&#039;<br \/>\nimport { ElMessage } from &#039;element-plus&#039;<\/p>\n<p>const userStore &#061; useUserStore()<br \/>\nconst router &#061; useRouter()<\/p>\n<p>const loginForm &#061; reactive({<br \/>\n  username: &#039;admin&#039;,<br \/>\n  password: &#039;123456&#039;<br \/>\n})<\/p>\n<p>async function handleLogin() {<br \/>\n  try {<br \/>\n    \/\/ \u53ea\u505a\u767b\u5f55\u62ff token&#xff0c;\u4e0d\u8981\u624b\u52a8\u8c03\u7528 getUserInfo&#xff01;<br \/>\n    await userStore.login(loginForm)<br \/>\n    \/\/ \u76f4\u63a5\u8df3\u8f6c\u9996\u9875&#xff0c;\u52a8\u6001\u8def\u7531\u52a0\u8f7d\u4ea4\u7ed9\u8def\u7531\u5b88\u536b<br \/>\n    router.push(&#039;\/dashboard\/index&#039;)<br \/>\n  } catch (e) {<br \/>\n    ElMessage.error(e.message)<br \/>\n  }<br \/>\n}<br \/>\n&lt;\/script&gt;<\/p>\n<p>&lt;style scoped&gt;<br \/>\n.login-container {<br \/>\n  background-color: #f5f7fa;<br \/>\n  min-height: 100vh;<br \/>\n}<br \/>\n&lt;\/style&gt;<\/p>\n<hr \/>\n<h4>\u6587\u4ef6 6&#xff1a;src\/layout\/components\/Sidebar\/index.vue&#xff08;\u4fa7\u8fb9\u680f\u83dc\u5355&#xff09;<\/h4>\n<p>&lt;template&gt;<br \/>\n  &lt;el-menu<br \/>\n    :collapse&#061;&#034;appStore.sidebarCollapse&#034;<br \/>\n    mode&#061;&#034;vertical&#034;<br \/>\n    router<br \/>\n    background-color&#061;&#034;#304156&#034;<br \/>\n    text-color&#061;&#034;#bfcbd9&#034;<br \/>\n    :default-active&#061;&#034;$route.path&#034;<br \/>\n    active-text-color&#061;&#034;#409eff&#034;&gt;<br \/>\n    &lt;!&#8211; \u5faa\u73af\u52a8\u6001\u8def\u7531\u6e32\u67d3\u83dc\u5355 &#8211;&gt;<br \/>\n    &lt;template<br \/>\n      v-for&#061;&#034;route in menuList&#034;<br \/>\n      :key&#061;&#034;route.path&#034;&gt;<br \/>\n      &lt;!&#8211; \u6709\u5b50\u8def\u7531\u7684\u60c5\u51b5 &#8211;&gt;<br \/>\n      &lt;el-sub-menu<br \/>\n        v-if&#061;&#034;route.children &amp;&amp; route.children.length &gt; 1&#034;<br \/>\n        :index&#061;&#034;route.path&#034;&gt;<br \/>\n        &lt;template #title&gt;<br \/>\n          &lt;el-icon&gt;&lt;component :is&#061;&#034;route.meta?.icon || &#039;Menu&#039;&#034; \/&gt;&lt;\/el-icon&gt;<br \/>\n          &lt;span&gt;{{ route.meta?.title }}&lt;\/span&gt;<br \/>\n        &lt;\/template&gt;<br \/>\n        &lt;el-menu-item<br \/>\n          v-for&#061;&#034;child in route.children&#034;<br \/>\n          :key&#061;&#034;child.path&#034;<br \/>\n          :index&#061;&#034;&#096;${route.path}\/${child.path}&#096;&#034;&gt;<br \/>\n          {{ child.meta?.title }}<br \/>\n        &lt;\/el-menu-item&gt;<br \/>\n      &lt;\/el-sub-menu&gt;<\/p>\n<p>      &lt;!&#8211; \u53ea\u6709\u4e00\u4e2a\u5b50\u8def\u7531\u7684\u60c5\u51b5&#xff0c;\u76f4\u63a5\u663e\u793a\u5b50\u8def\u7531 &#8211;&gt;<br \/>\n      &lt;el-menu-item<br \/>\n        v-else-if&#061;&#034;route.children &amp;&amp; route.children.length &#061;&#061;&#061; 1&#034;<br \/>\n        :index&#061;&#034;&#096;${route.path}\/${route.children[0].path}&#096;&#034;&gt;<br \/>\n        &lt;el-icon&gt;&lt;component :is&#061;&#034;route.meta?.icon || &#039;Menu&#039;&#034; \/&gt;&lt;\/el-icon&gt;<br \/>\n        &lt;template #title&gt;{{ route.children[0].meta?.title }}&lt;\/template&gt;<br \/>\n      &lt;\/el-menu-item&gt;<br \/>\n    &lt;\/template&gt;<br \/>\n  &lt;\/el-menu&gt;<br \/>\n&lt;\/template&gt;<\/p>\n<p>&lt;script setup&gt;<br \/>\n  import { computed } from &#039;vue&#039;<br \/>\n  import { useUserStore } from &#039;&#064;\/stores\/user&#039;<br \/>\n  import { useAppStore } from &#039;&#064;\/stores\/app&#039;<br \/>\n  \/\/ \u624b\u52a8\u5bfc\u5165\u7528\u5230\u7684\u56fe\u6807<br \/>\n  import { House, Setting, Menu } from &#039;&#064;element-plus\/icons-vue&#039;<\/p>\n<p>  const userStore &#061; useUserStore()<br \/>\n  const appStore &#061; useAppStore()<\/p>\n<p>  \/\/ \u56fe\u6807\u6620\u5c04<br \/>\n  const iconMap &#061; { House, Setting, Menu }<\/p>\n<p>  \/\/ \u4ece store \u8bfb\u53d6\u52a8\u6001\u8def\u7531&#xff0c;\u751f\u6210\u83dc\u5355<br \/>\n  const menuList &#061; computed(() &#061;&gt; {<br \/>\n    return userStore.addRoutes.map((route) &#061;&gt; ({<br \/>\n      &#8230;route,<br \/>\n      meta: {<br \/>\n        &#8230;route.meta,<br \/>\n        icon: iconMap[route.meta?.icon] || Menu<br \/>\n      }<br \/>\n    }))<br \/>\n  })<br \/>\n&lt;\/script&gt;<\/p>\n<hr \/>\n<h3>\u4e09\u3001\u5b8c\u6574\u6267\u884c\u6d41\u7a0b&#xff08;\u4e00\u6b65\u4e00\u6b65\u8d70&#xff09;<\/h3>\n<li>\u8bbf\u95ee\u9875\u9762 \u2192 \u8fdb\u5165\u767b\u5f55\u9875&#xff0c;token \u4e3a\u7a7a<\/li>\n<li>\u70b9\u51fb\u767b\u5f55 \u2192 \u8c03\u7528 \/login \u63a5\u53e3 \u2192 \u62ff\u5230 token \u2192 \u5b58\u5165 Pinia &#043; localStorage<\/li>\n<li>\u8df3\u8f6c\u9996\u9875 \u2192 router.push(&#039;\/dashboard\/index&#039;) \u2192 \u89e6\u53d1 beforeEach \u5b88\u536b<\/li>\n<li>\u5b88\u536b\u5224\u65ad \u2192 \u6709 token&#xff0c;\u4e0d\u662f\u767b\u5f55\u9875&#xff0c;roles \u4e3a\u7a7a \u2192 \u8fdb\u5165\u52a0\u8f7d\u52a8\u6001\u8def\u7531\u903b\u8f91<\/li>\n<li>\u8c03\u7528\u63a5\u53e3 \u2192 await userStore.getUserInfo() \u2192 \u8c03\u7528 \/getUserInfo \u2192 \u62ff\u5230 routes \u6570\u7ec4<\/li>\n<li>\u8f6c\u6362\u8def\u7531 \u2192 filterAsyncRoutes() \u628a\u5b57\u7b26\u4e32 component \u8f6c\u6210\u771f\u5b9e Vue \u7ec4\u4ef6<\/li>\n<li>\u6ce8\u518c\u8def\u7531 \u2192 accessRoutes.forEach(route &#061;&gt; router.addRoute(route))<\/li>\n<li>\u6ce8\u518c 404 \u2192 \u6700\u540e\u6dfb\u52a0\u901a\u914d\u8def\u7531<\/li>\n<li>\u91cd\u65b0\u5bfc\u822a \u2192 return { &#8230;to, replace: true } \u2192 \u91cd\u65b0\u8bbf\u95ee \/dashboard\/index<\/li>\n<li>\u8def\u7531\u5339\u914d \u2192 \u6b64\u65f6\u8def\u7531\u8868\u5df2\u6709 \/dashboard\/index \u2192 \u6e32\u67d3 Layout \u5e03\u5c40<\/li>\n<li>\u6e32\u67d3\u83dc\u5355 \u2192 Sidebar \u8bfb\u53d6 userStore.addRoutes \u2192 \u5faa\u73af\u6e32\u67d3\u4fa7\u8fb9\u680f\u83dc\u5355<\/li>\n<li>\u9875\u9762\u663e\u793a \u2192 \u5de5\u4f5c\u53f0\u9875\u9762\u6b63\u5e38\u663e\u793a<\/li>\n<hr \/>\n<h3>\u56db\u3001\u9ad8\u9891\u8e29\u5751\u6e05\u5355&#xff08;\u5fc5\u770b&#xff09;<\/h3>\n<p>\u8868\u683c<\/p>\n<table>\n<tr>\u5751\u73b0\u8c61\u89e3\u51b3\u65b9\u6848<\/tr>\n<tbody>\n<tr>\n<td>mock \u767b\u5f55\u63a5\u53e3\u6ca1\u8fd4\u56de token<\/td>\n<td>token &#061; undefined&#xff0c;\u5b88\u536b\u903b\u8f91\u9519\u4e71<\/td>\n<td>\u786e\u4fdd \/login \u8fd4\u56de data.token<\/td>\n<\/tr>\n<tr>\n<td>\u767b\u5f55\u9875\u624b\u52a8\u8c03\u7528 getUserInfo<\/td>\n<td>\u65f6\u5e8f\u6df7\u4e71&#xff0c;\u8def\u7531\u6ca1\u6ce8\u518c\u5c31\u8df3\u8f6c<\/td>\n<td>\u767b\u5f55\u9875\u53ea\u767b\u5f55&#xff0c;\u52a8\u6001\u8def\u7531\u4ea4\u7ed9\u5b88\u536b<\/td>\n<\/tr>\n<tr>\n<td>404 \u901a\u914d\u8def\u7531\u6ce8\u518c\u592a\u65e9<\/td>\n<td>\u6240\u6709\u9875\u9762\u90fd\u8df3 404<\/td>\n<td>\u5fc5\u987b\u5728\u6240\u6709\u4e1a\u52a1\u8def\u7531 addRoute \u4e4b\u540e\u518d\u6ce8\u518c<\/td>\n<\/tr>\n<tr>\n<td>addRoute \u540e\u6ca1\u91cd\u65b0\u5bfc\u822a<\/td>\n<td>\u62a5 No match found<\/td>\n<td>\u5fc5\u987b return { &#8230;to, replace: true }<\/td>\n<\/tr>\n<tr>\n<td>Layout \u6ca1\u52a0 markRaw<\/td>\n<td>Vue \u8b66\u544a\u7ec4\u4ef6\u88ab\u53d8\u6210\u54cd\u5e94\u5f0f<\/td>\n<td>route.component &#061; markRaw(Layout)<\/td>\n<\/tr>\n<tr>\n<td>\u7528\u6a21\u677f\u5b57\u7b26\u4e32\u52a8\u6001 import<\/td>\n<td>Vite \u62a5\u9519 Unknown variable dynamic import<\/td>\n<td>\u7528 import.meta.glob \u9884\u626b\u63cf<\/td>\n<\/tr>\n<tr>\n<td>mock \u7684 component \u8def\u5f84\u5199\u9519<\/td>\n<td>\u9875\u9762\u7a7a\u767d&#xff0c;\u7ec4\u4ef6\u627e\u4e0d\u5230<\/td>\n<td>\u786e\u4fdd\u548c views \u4e0b\u6587\u4ef6\u8def\u5f84\u4e00\u81f4<\/td>\n<\/tr>\n<tr>\n<td>\u5237\u65b0\u9875\u9762\u767d\u5c4f<\/td>\n<td>\u52a8\u6001\u8def\u7531\u6ca1\u91cd\u65b0\u52a0\u8f7d<\/td>\n<td>\u5b88\u536b\u91cc\u5224\u65ad roles \u4e3a\u7a7a\u5c31\u91cd\u65b0\u52a0\u8f7d<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u4e94\u3001\u6d4b\u8bd5\u6b65\u9aa4&#xff08;\u4e25\u683c\u6309\u987a\u5e8f&#xff09;<\/h3>\n<li>\u5168\u90e8\u4fdd\u5b58\u6587\u4ef6&#xff0c;\u505c\u6b62\u7ec8\u7aef&#xff0c;\u91cd\u65b0\u6267\u884c pnpm dev<\/li>\n<li>F12 \u2192 Application \u2192 Local Storage \u2192 \u6e05\u7a7a\u6240\u6709\u6570\u636e<\/li>\n<li>\u5237\u65b0\u6d4f\u89c8\u5668&#xff0c;\u56de\u5230\u767b\u5f55\u9875<\/li>\n<li>\u8f93\u5165 admin \/ 123456&#xff0c;\u70b9\u51fb\u767b\u5f55<\/li>\n<li>\u89c2\u5bdf\u63a7\u5236\u53f0\u6253\u5370\u987a\u5e8f&#xff1a;<\/li>\n<p>\u65ad\u70b9&#061;&#061;111&#061;&#061; mock-token-123456   \u2190 token \u6709\u503c<br \/>\n\u65ad\u70b9&#061;&#061;222&#061;&#061; mock-token-123456<br \/>\naccessRoutes&#061;&#061;&#061;&#061; Proxy(Array)     \u2190 \u8def\u7531\u6570\u7ec4\u6709\u5185\u5bb9<\/p>\n<li>\u9884\u671f\u7ed3\u679c&#xff1a;\n<ul>\n<li>\u9875\u9762\u6b63\u5e38\u8fdb\u5165\u5de5\u4f5c\u53f0&#xff0c;\u4e0d\u767d\u5c4f\u3001\u4e0d 404 \u2714<\/li>\n<li>\u4fa7\u8fb9\u680f\u51fa\u73b0\u3010\u5de5\u4f5c\u53f0\u3011\u3010\u7cfb\u7edf\u7ba1\u7406\u3011\u83dc\u5355 \u2714<\/li>\n<li>\u70b9\u51fb\u3010\u7528\u6237\u7ba1\u7406\u3011&#xff0c;\u6253\u5f00\u7528\u6237\u5217\u8868\u9875\u9762 \u2714<\/li>\n<li>\u6309 F5 \u5237\u65b0\u9875\u9762&#xff0c;\u4f9d\u65e7\u6b63\u5e38\u663e\u793a \u2714<\/li>\n<li>\u9000\u51fa\u767b\u5f55\u540e&#xff0c;\u518d\u767b\u5f55&#xff0c;\u83dc\u5355\u6b63\u5e38\u6e32\u67d3 \u2714<\/li>\n<\/ul>\n<\/li>\n<hr \/>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260905000101-6a9b5bbdcfa45.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7b2c\u5341\u56db\u8282&#xff1a;\u540e\u7aef\u8fd4\u56de\u6743\u9650\u52a8\u6001\u8def\u7531\u76ee\u6807&#xff1a;\u767b\u5f55\u540e\u4ece\u540e\u7aef&#xff08;mock&#xff09;\u83b7\u53d6\u8be5\u7528\u6237\u53ef\u8bbf\u95ee\u7684\u83dc\u5355\u8def\u7531&#xff0c;\u52a8\u6001\u6ce8\u518c\u5230\u8def\u7531\u7cfb\u7edf&#xff0c;\u4fa7\u8fb9\u680f\u83dc\u5355\u6839\u636e\u8fd4\u56de\u7684\u8def\u7531\u81ea\u52a8\u6e32\u67d3\u3002\u4e0d\u540c\u89d2\u8272\u8fd4\u56de\u4e0d\u540c\u8def\u7531&#xff0c;\u5b9e\u73b0\u6743\u9650\u63a7\u5236\u3002\u4e00\u3001\u5148\u641e\u61c2\u539f\u7406&#xff08;\u975e\u5e38\u91cd\u8981&#xff09;<br \/>\n\u4f20\u7edf\u5199\u6b7b\u8def\u7531\u7684\u65b9\u5f0f&#xff1a;<br \/>\nrouter\/index.js \u91cc\u5199\u6b7b\u6240\u6709\u8def\u7531 \u2192 \u9879\u76ee\u542f\u52a8\u5c31\u5168\u90e8\u6ce8\u518c \u2192 \u6240\u6709\u4eba\u90fd\u80fd\u8bbf\u95ee\u6240\u6709\u9875\u9762\u52a8\u6001\u8def\u7531\u7684\u65b9\u5f0f<\/p>\n","protected":false},"author":2,"featured_media":100743,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[187,625,87],"topic":[],"class_list":["post-100744","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-javascript","tag-vue-js","tag-87"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u7b2c\u5341\u56db\u8282\uff1a\u540e\u7aef\u8fd4\u56de\u6743\u9650\u52a8\u6001\u8def\u7531 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/100744.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u7b2c\u5341\u56db\u8282\uff1a\u540e\u7aef\u8fd4\u56de\u6743\u9650\u52a8\u6001\u8def\u7531 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u7b2c\u5341\u56db\u8282&#xff1a;\u540e\u7aef\u8fd4\u56de\u6743\u9650\u52a8\u6001\u8def\u7531\u76ee\u6807&#xff1a;\u767b\u5f55\u540e\u4ece\u540e\u7aef&#xff08;mock&#xff09;\u83b7\u53d6\u8be5\u7528\u6237\u53ef\u8bbf\u95ee\u7684\u83dc\u5355\u8def\u7531&#xff0c;\u52a8\u6001\u6ce8\u518c\u5230\u8def\u7531\u7cfb\u7edf&#xff0c;\u4fa7\u8fb9\u680f\u83dc\u5355\u6839\u636e\u8fd4\u56de\u7684\u8def\u7531\u81ea\u52a8\u6e32\u67d3\u3002\u4e0d\u540c\u89d2\u8272\u8fd4\u56de\u4e0d\u540c\u8def\u7531&#xff0c;\u5b9e\u73b0\u6743\u9650\u63a7\u5236\u3002\u4e00\u3001\u5148\u641e\u61c2\u539f\u7406&#xff08;\u975e\u5e38\u91cd\u8981&#xff09; \u4f20\u7edf\u5199\u6b7b\u8def\u7531\u7684\u65b9\u5f0f&#xff1a; router\/index.js \u91cc\u5199\u6b7b\u6240\u6709\u8def\u7531 \u2192 \u9879\u76ee\u542f\u52a8\u5c31\u5168\u90e8\u6ce8\u518c \u2192 \u6240\u6709\u4eba\u90fd\u80fd\u8bbf\u95ee\u6240\u6709\u9875\u9762\u52a8\u6001\u8def\u7531\u7684\u65b9\u5f0f\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/100744.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-05T00:01:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260905000101-6a9b5bbdcfa45.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/100744.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/100744.html\",\"name\":\"\u7b2c\u5341\u56db\u8282\uff1a\u540e\u7aef\u8fd4\u56de\u6743\u9650\u52a8\u6001\u8def\u7531 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-05T00:01:03+00:00\",\"dateModified\":\"2026-09-05T00:01:03+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/100744.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/100744.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/100744.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u7b2c\u5341\u56db\u8282\uff1a\u540e\u7aef\u8fd4\u56de\u6743\u9650\u52a8\u6001\u8def\u7531\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u7b2c\u5341\u56db\u8282\uff1a\u540e\u7aef\u8fd4\u56de\u6743\u9650\u52a8\u6001\u8def\u7531 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/100744.html","og_locale":"zh_CN","og_type":"article","og_title":"\u7b2c\u5341\u56db\u8282\uff1a\u540e\u7aef\u8fd4\u56de\u6743\u9650\u52a8\u6001\u8def\u7531 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u7b2c\u5341\u56db\u8282&#xff1a;\u540e\u7aef\u8fd4\u56de\u6743\u9650\u52a8\u6001\u8def\u7531\u76ee\u6807&#xff1a;\u767b\u5f55\u540e\u4ece\u540e\u7aef&#xff08;mock&#xff09;\u83b7\u53d6\u8be5\u7528\u6237\u53ef\u8bbf\u95ee\u7684\u83dc\u5355\u8def\u7531&#xff0c;\u52a8\u6001\u6ce8\u518c\u5230\u8def\u7531\u7cfb\u7edf&#xff0c;\u4fa7\u8fb9\u680f\u83dc\u5355\u6839\u636e\u8fd4\u56de\u7684\u8def\u7531\u81ea\u52a8\u6e32\u67d3\u3002\u4e0d\u540c\u89d2\u8272\u8fd4\u56de\u4e0d\u540c\u8def\u7531&#xff0c;\u5b9e\u73b0\u6743\u9650\u63a7\u5236\u3002\u4e00\u3001\u5148\u641e\u61c2\u539f\u7406&#xff08;\u975e\u5e38\u91cd\u8981&#xff09; \u4f20\u7edf\u5199\u6b7b\u8def\u7531\u7684\u65b9\u5f0f&#xff1a; router\/index.js \u91cc\u5199\u6b7b\u6240\u6709\u8def\u7531 \u2192 \u9879\u76ee\u542f\u52a8\u5c31\u5168\u90e8\u6ce8\u518c \u2192 \u6240\u6709\u4eba\u90fd\u80fd\u8bbf\u95ee\u6240\u6709\u9875\u9762\u52a8\u6001\u8def\u7531\u7684\u65b9\u5f0f","og_url":"https:\/\/www.wsisp.com\/helps\/100744.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-05T00:01:03+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260905000101-6a9b5bbdcfa45.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/100744.html","url":"https:\/\/www.wsisp.com\/helps\/100744.html","name":"\u7b2c\u5341\u56db\u8282\uff1a\u540e\u7aef\u8fd4\u56de\u6743\u9650\u52a8\u6001\u8def\u7531 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-05T00:01:03+00:00","dateModified":"2026-09-05T00:01:03+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/100744.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/100744.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/100744.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u7b2c\u5341\u56db\u8282\uff1a\u540e\u7aef\u8fd4\u56de\u6743\u9650\u52a8\u6001\u8def\u7531"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/100744","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=100744"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/100744\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/100743"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=100744"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=100744"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=100744"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=100744"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}