{"id":8283,"date":"2023-11-28T20:22:40","date_gmt":"2023-11-28T12:22:40","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=8283"},"modified":"2023-12-02T22:22:20","modified_gmt":"2023-12-02T14:22:20","slug":"vue-zhongvuex-shi-shen-me-zen-me-shi-yong-na-zhong-2","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/11\/28\/vue-zhongvuex-shi-shen-me-zen-me-shi-yong-na-zhong-2\/","title":{"rendered":"Vue \u4e2d vuex \u662f\u4ec0\u4e48\uff1f\u600e\u4e48\u4f7f\u7528\uff1f\u54ea\u79cd\u529f\u80fd\u573a\u666f\u4f7f\u7528\u5b83\uff1f"},"content":{"rendered":"<p>Vuex \u662f Vue.js \u5b98\u65b9\u63d0\u4f9b\u7684\u72b6\u6001\u7ba1\u7406\u5e93\uff0c\u7528\u4e8e\u7ba1\u7406 Vue \u5e94\u7528\u4e2d\u7684\u72b6\u6001\u3002\u5b83\u4e13\u95e8\u7528\u4e8e\u89e3\u51b3 Vue \u5e94\u7528\u4e2d\u591a\u4e2a\u7ec4\u4ef6\u5171\u4eab\u72b6\u6001\u3001\u6570\u636e\u5171\u4eab\u548c\u72b6\u6001\u7ba1\u7406\u7684\u95ee\u9898\u3002<\/p>\n<h3><a id=\"%E4%B8%BB%E8%A6%81%E5%8A%9F%E8%83%BD%EF%BC%9A\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u4e3b\u8981\u529f\u80fd\uff1a<\/h3>\n<ol>\n<li>\n<p><strong>\u96c6\u4e2d\u5f0f\u5b58\u50a8\uff1a<\/strong> Vuex \u63d0\u4f9b\u4e86\u4e00\u4e2a\u96c6\u4e2d\u5f0f\u7684\u5b58\u50a8\u4ed3\u5e93\uff08store\uff09\uff0c\u7528\u4e8e\u5b58\u653e\u5e94\u7528\u4e2d\u7684\u6240\u6709\u7ec4\u4ef6\u7684\u72b6\u6001\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u72b6\u6001\u7ba1\u7406\uff1a<\/strong> \u53ef\u4ee5\u901a\u8fc7 <code>state<\/code> \u5c5e\u6027\u5b58\u50a8\u5e94\u7528\u7ea7\u522b\u7684\u72b6\u6001\u6570\u636e\uff0c\u5e76\u901a\u8fc7 <code>getters<\/code> \u8ba1\u7b97\u5c5e\u6027\u3001<code>mutations<\/code> \u4fee\u6539\u72b6\u6001\u3001<code>actions<\/code> \u5904\u7406\u5f02\u6b65\u64cd\u4f5c\u6765\u7ba1\u7406\u72b6\u6001\u7684\u8bfb\u5199\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u54cd\u5e94\u5f0f\u66f4\u65b0\uff1a<\/strong> Vuex \u7684\u72b6\u6001\u662f\u54cd\u5e94\u5f0f\u7684\uff0c\u5f53\u72b6\u6001\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u4f9d\u8d56\u4e8e\u8be5\u72b6\u6001\u7684\u7ec4\u4ef6\u4f1a\u81ea\u52a8\u66f4\u65b0\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u7ec4\u4ef6\u901a\u4fe1\uff1a<\/strong> \u901a\u8fc7 <code>state<\/code>\u3001<code>getters<\/code>\u3001<code>mutations<\/code> \u548c <code>actions<\/code>\uff0cVuex \u63d0\u4f9b\u4e86\u4e00\u79cd\u5728\u7ec4\u4ef6\u4e4b\u95f4\u4f20\u9012\u6570\u636e\u7684\u673a\u5236\uff0c\u4f7f\u5f97\u7ec4\u4ef6\u4e4b\u95f4\u7684\u6570\u636e\u4f20\u9012\u66f4\u52a0\u65b9\u4fbf\u548c\u9ad8\u6548\u3002<\/p>\n<\/li>\n<\/ol>\n<h3><a id=\"%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95%EF%BC%9A\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u4f7f\u7528\u65b9\u6cd5\uff1a<\/h3>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5 Vuex\uff1a<\/strong> \u5728 Vue.js \u9879\u76ee\u4e2d\u5b89\u88c5 Vuex\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa store\uff1a<\/strong> \u521b\u5efa\u4e00\u4e2a Vuex store\uff0c\u5305\u542b <code>state<\/code>\u3001<code>getters<\/code>\u3001<code>mutations<\/code> \u548c <code>actions<\/code>\uff0c\u5e76\u901a\u8fc7 <code>new Vuex.Store()<\/code> \u5b9e\u4f8b\u5316\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u5728 Vue \u5b9e\u4f8b\u4e2d\u4f7f\u7528 Vuex\uff1a<\/strong> \u5728 Vue \u5b9e\u4f8b\u4e2d\u6ce8\u518c Vuex store\uff0c\u5e76\u901a\u8fc7 <code>$store<\/code> \u5c5e\u6027\u5728\u7ec4\u4ef6\u4e2d\u8bbf\u95ee\u72b6\u6001\u548c\u65b9\u6cd5\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u5728\u7ec4\u4ef6\u4e2d\u4f7f\u7528 Vuex\uff1a<\/strong> \u5728\u7ec4\u4ef6\u4e2d\u901a\u8fc7 <code>$store.state<\/code> \u8bbf\u95ee\u72b6\u6001\u3001\u901a\u8fc7 <code>$store.getters<\/code> \u8bbf\u95ee\u8ba1\u7b97\u5c5e\u6027\u3001\u901a\u8fc7 <code>$store.commit<\/code> \u89e6\u53d1 mutation\u3001\u901a\u8fc7 <code>$store.dispatch<\/code> \u89e6\u53d1 action\u3002<\/p>\n<\/li>\n<\/ol>\n<h3><a id=\"%E9%80%82%E7%94%A8%E5%9C%BA%E6%99%AF%EF%BC%9A\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u9002\u7528\u573a\u666f\uff1a<\/h3>\n<ul>\n<li>\n<p><strong>\u5927\u578b\u5e94\u7528\uff1a<\/strong> \u9002\u7528\u4e8e\u9700\u8981\u7ba1\u7406\u591a\u4e2a\u7ec4\u4ef6\u5171\u4eab\u72b6\u6001\u7684\u5927\u578b\u5e94\u7528\uff0c\u7279\u522b\u662f\u6d89\u53ca\u5230\u591a\u4e2a\u7ec4\u4ef6\u4e4b\u95f4\u9891\u7e41\u7684\u72b6\u6001\u4ea4\u4e92\u548c\u6570\u636e\u5171\u4eab\u7684\u573a\u666f\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u590d\u6742\u6570\u636e\u6d41\uff1a<\/strong> \u5f53\u5e94\u7528\u4e2d\u7684\u72b6\u6001\u8f83\u4e3a\u590d\u6742\uff0c\u9700\u8981\u5bf9\u72b6\u6001\u8fdb\u884c\u96c6\u4e2d\u7ba1\u7406\u548c\u63a7\u5236\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528 Vuex \u6765\u66f4\u597d\u5730\u7ec4\u7ec7\u548c\u7ba1\u7406\u6570\u636e\u6d41\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u8de8\u7ec4\u4ef6\u901a\u4fe1\uff1a<\/strong> \u5bf9\u4e8e\u9700\u8981\u8de8\u7ec4\u4ef6\u5171\u4eab\u6570\u636e\u6216\u8fdb\u884c\u7ec4\u4ef6\u901a\u4fe1\u7684\u60c5\u51b5\uff0cVuex \u63d0\u4f9b\u4e86\u4e00\u79cd\u4fbf\u6377\u7684\u65b9\u5f0f\u6765\u5904\u7406\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u603b\u7684\u6765\u8bf4\uff0cVuex \u66f4\u9002\u5408\u4e8e\u5927\u578b\u6216\u590d\u6742\u7684 Vue.js \u5e94\u7528\uff0c\u7528\u4e8e\u7edf\u4e00\u7ba1\u7406\u5e94\u7528\u7684\u72b6\u6001\uff0c\u63d0\u9ad8\u72b6\u6001\u7684\u53ef\u7ef4\u62a4\u6027\u548c\u53ef\u6d4b\u8bd5\u6027\uff0c\u5e76\u7b80\u5316\u4e86\u7ec4\u4ef6\u4e4b\u95f4\u6570\u636e\u4f20\u9012\u548c\u72b6\u6001\u7ba1\u7406\u7684\u590d\u6742\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Vuex \u662f Vue.js \u5b98\u65b9\u63d0\u4f9b\u7684\u72b6\u6001\u7ba1\u7406\u5e93\uff0c\u7528\u4e8e\u7ba1\u7406 Vue \u5e94\u7528\u4e2d\u7684\u72b6\u6001\u3002\u5b83\u4e13\u95e8\u7528\u4e8e\u89e3\u51b3 Vue \u5e94\u7528 [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[114],"tags":[],"class_list":["post-8283","post","type-post","status-publish","format-standard","hentry","category-vue"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/8283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=8283"}],"version-history":[{"count":2,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/8283\/revisions"}],"predecessor-version":[{"id":14083,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/8283\/revisions\/14083"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=8283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=8283"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=8283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}