mirror of
https://github.com/sunniejs/vue-h5-template.git
synced 2025-04-06 03:57:50 +08:00
34 lines
7.8 KiB
JavaScript
34 lines
7.8 KiB
JavaScript
import{_ as s,o as a,c as n,d as p}from"./app.0ed445b7.js";const i=JSON.parse('{"title":"Vuex \u72B6\u6001\u7BA1\u7406","description":"","frontmatter":{},"headers":[],"relativePath":"guide/vue2/vuex.md","lastUpdated":1672820852000}'),l={name:"guide/vue2/vuex.md"},o=p(`<h1 id="vuex-\u72B6\u6001\u7BA1\u7406" tabindex="-1">Vuex \u72B6\u6001\u7BA1\u7406 <a class="header-anchor" href="#vuex-\u72B6\u6001\u7BA1\u7406" aria-hidden="true">#</a></h1><p>\u76EE\u5F55\u7ED3\u6784</p><div class="language-bash"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki"><code><span class="line"><span style="color:#A6ACCD;">\u251C\u2500\u2500 store</span></span>
|
|
<span class="line"><span style="color:#A6ACCD;">\u2502 \u251C\u2500\u2500 modules</span></span>
|
|
<span class="line"><span style="color:#A6ACCD;">\u2502 \u2502 \u2514\u2500\u2500 app.js</span></span>
|
|
<span class="line"><span style="color:#A6ACCD;">\u2502 \u251C\u2500\u2500 index.js</span></span>
|
|
<span class="line"><span style="color:#A6ACCD;">\u2502 \u251C\u2500\u2500 getters.js</span></span>
|
|
<span class="line"></span></code></pre></div><p><code>main.js</code> \u5F15\u5165</p><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre class="shiki"><code><span class="line"><span style="color:#89DDFF;">import</span><span style="color:#A6ACCD;"> Vue </span><span style="color:#89DDFF;">from</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">"</span><span style="color:#C3E88D;">vue</span><span style="color:#89DDFF;">"</span><span style="color:#89DDFF;">;</span></span>
|
|
<span class="line"><span style="color:#89DDFF;">import</span><span style="color:#A6ACCD;"> App </span><span style="color:#89DDFF;">from</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">"</span><span style="color:#C3E88D;">./App.vue</span><span style="color:#89DDFF;">"</span><span style="color:#89DDFF;">;</span></span>
|
|
<span class="line"><span style="color:#89DDFF;">import</span><span style="color:#A6ACCD;"> store </span><span style="color:#89DDFF;">from</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">"</span><span style="color:#C3E88D;">./store</span><span style="color:#89DDFF;">"</span><span style="color:#89DDFF;">;</span></span>
|
|
<span class="line"><span style="color:#89DDFF;">new</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">Vue</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">{</span></span>
|
|
<span class="line"><span style="color:#A6ACCD;"> </span><span style="color:#F07178;">el</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">"</span><span style="color:#C3E88D;">#app</span><span style="color:#89DDFF;">"</span><span style="color:#89DDFF;">,</span></span>
|
|
<span class="line"><span style="color:#A6ACCD;"> router</span><span style="color:#89DDFF;">,</span></span>
|
|
<span class="line"><span style="color:#A6ACCD;"> store</span><span style="color:#89DDFF;">,</span></span>
|
|
<span class="line"><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">render</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;">h</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">=></span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">h</span><span style="color:#A6ACCD;">(App)</span><span style="color:#89DDFF;">,</span></span>
|
|
<span class="line"><span style="color:#89DDFF;">}</span><span style="color:#A6ACCD;">)</span><span style="color:#89DDFF;">;</span></span>
|
|
<span class="line"></span></code></pre></div><p>\u4F7F\u7528</p><div class="language-html"><button title="Copy Code" class="copy"></button><span class="lang">html</span><pre class="shiki"><code><span class="line"><span style="color:#89DDFF;"><</span><span style="color:#F07178;">script</span><span style="color:#89DDFF;">></span></span>
|
|
<span class="line"><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">import</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">mapGetters</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">}</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">from</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">"</span><span style="color:#C3E88D;">vuex</span><span style="color:#89DDFF;">"</span><span style="color:#89DDFF;">;</span></span>
|
|
<span class="line"><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">export</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">default</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span></span>
|
|
<span class="line"><span style="color:#A6ACCD;"> </span><span style="color:#F07178;">computed</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span></span>
|
|
<span class="line"><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">...</span><span style="color:#82AAFF;">mapGetters</span><span style="color:#A6ACCD;">([</span><span style="color:#89DDFF;">"</span><span style="color:#C3E88D;">userName</span><span style="color:#89DDFF;">"</span><span style="color:#A6ACCD;">])</span><span style="color:#89DDFF;">,</span></span>
|
|
<span class="line"><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">},</span></span>
|
|
<span class="line"></span>
|
|
<span class="line"><span style="color:#A6ACCD;"> </span><span style="color:#F07178;">methods</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span></span>
|
|
<span class="line"><span style="color:#89DDFF;"> </span><span style="color:#676E95;">// Action \u901A\u8FC7 store.dispatch \u65B9\u6CD5\u89E6\u53D1</span></span>
|
|
<span class="line"><span style="color:#A6ACCD;"> </span><span style="color:#F07178;">doDispatch</span><span style="color:#89DDFF;">()</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span></span>
|
|
<span class="line"><span style="color:#F07178;"> </span><span style="color:#89DDFF;">this.</span><span style="color:#A6ACCD;">$store</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">dispatch</span><span style="color:#F07178;">(</span></span>
|
|
<span class="line"><span style="color:#F07178;"> </span><span style="color:#89DDFF;">"</span><span style="color:#C3E88D;">setUserName</span><span style="color:#89DDFF;">"</span><span style="color:#89DDFF;">,</span></span>
|
|
<span class="line"><span style="color:#F07178;"> </span><span style="color:#89DDFF;">"</span><span style="color:#C3E88D;">\u771F\u4E56\uFF0C\u8D76\u7D27\u5173\u6CE8\u516C\u4F17\u53F7\uFF0C\u7EC4\u7EC7\u90FD\u5728\u7B49\u4F60~</span><span style="color:#89DDFF;">"</span></span>
|
|
<span class="line"><span style="color:#F07178;"> )</span><span style="color:#89DDFF;">;</span></span>
|
|
<span class="line"><span style="color:#F07178;"> </span><span style="color:#89DDFF;">},</span></span>
|
|
<span class="line"><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">},</span></span>
|
|
<span class="line"><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">};</span></span>
|
|
<span class="line"><span style="color:#89DDFF;"></</span><span style="color:#F07178;">script</span><span style="color:#89DDFF;">></span></span>
|
|
<span class="line"></span></code></pre></div>`,7),e=[o];function t(c,r,D,F,y,A){return a(),n("div",null,e)}const u=s(l,[["render",t]]);export{i as __pageData,u as default};
|