{"id":1013,"date":"2023-03-12T09:22:55","date_gmt":"2023-03-12T01:22:55","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1013"},"modified":"2023-04-29T13:16:15","modified_gmt":"2023-04-29T05:16:15","slug":"directly-obtain-vuex-status-state-data-from-vue-component","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/12\/directly-obtain-vuex-status-state-data-from-vue-component\/","title":{"rendered":"Vue\u7ec4\u4ef6\u4e2d\u76f4\u63a5\u83b7\u53d6Vuex\u72b6\u6001state\u6570\u636e"},"content":{"rendered":"<p>account.js<\/p>\n<pre><code class=\"language-javascript\">export default {\n  state: {\n    user: {\n      &#039;data&#039;: null\n      &#039;success&#039;: false,\n      &#039;timestamp&#039;: 0\n    }\n  },\n  mutations: {\n    ...\n  },\n  actions: {\n    ...\n  }\n}<\/code><\/pre>\n<p><!-- more --><\/p>\n<p>\u5728\u53e6\u4e00\u4e2a\u7ec4\u4ef6\u4e2d\u83b7\u53d6user\u6570\u636e<\/p>\n<pre><code class=\"language-javascript\">export default {\n  created () {\n    let user = this.$store.state.account.user.data\n    console.log(user)\n  },\n}<\/code><\/pre>\n<blockquote>\n<p>\u6ce8\uff1a\u4f7f\u7528$store\u7684\u524d\u63d0\u662f\u5728main.js\u4e2d\u521d\u59cb\u5316Vue\u65f6\u52a0\u8f7dstore\/index.js<\/p>\n<\/blockquote>\n<p>main.js<\/p>\n<pre><code class=\"language-javascript\">import Vue from &#039;vue&#039;\nimport App from &#039;.\/App&#039;\nimport router from &#039;.\/router&#039;\nimport store from &#039;.\/store\/index.js&#039;\n\n\/* eslint-disable no-new *\/\nnew Vue({\n  el: &#039;#app&#039;,\n  router,\n  store,\n  components: { App },\n  template: &#039;&lt;App\/&gt;&#039;\n})<\/code><\/pre>\n<p>store\/index.js<\/p>\n<pre><code class=\"language-javascript\">import Vue from &#039;vue&#039;\nimport Vuex from &#039;vuex&#039;\nimport * as getters from &#039;.\/getters&#039;\n\nimport account from &#039;.\/modules\/account&#039;\n\nVue.use(Vuex)\nconst debug = process.env.NODE_ENV !== &#039;production&#039;\n\nexport default new Vuex.Store({\n  getters,\n  modules: {\n    account\n  },\n  strict: debug\n})<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>account.js export default { state: { user: { &#039;data [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[279],"class_list":["post-1013","post","type-post","status-publish","format-standard","hentry","category-vue","tag-vuex"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1013","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1013"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1013\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1013"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1013"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1013"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}