{"id":10053,"date":"2020-04-12T19:22:19","date_gmt":"2020-04-12T10:22:19","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=10053"},"modified":"2023-05-27T23:59:29","modified_gmt":"2023-05-27T14:59:29","slug":"%e3%80%90vue-js%e3%80%91%e3%82%b3%e3%83%b3%e3%83%9d%e3%83%bc%e3%83%8d%e3%83%b3%e3%83%88%e3%81%8b%e3%82%89%e3%80%8cvuex%e3%80%8d%e3%82%92%e5%91%bc%e3%81%b3%e5%87%ba%e3%81%99%e3%80%82","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=10053","title":{"rendered":"\u3010Vue.js\u3011\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304b\u3089\u300cVuex\u300d\u3092\u547c\u3073\u51fa\u3059\u3002"},"content":{"rendered":"<p>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304b\u3089Vuex\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u306b\u306f\u4e8c\u3064\u306e\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>this.$store\u306b\u3088\u308a\u76f4\u63a5\u4f7f\u3046\u65b9\u6cd5<\/li>\n<li>Vuex\u304c\u63d0\u4f9b\u3057\u3066\u3044\u308b\u30d8\u30eb\u30d1\u30fc\u95a2\u6570\u3092\u4f7f\u7528\u3059\u308b\u65b9\u6cd5<\/li>\n<\/ul>\n<h2>this.$store\u306b\u3088\u308b\u30a2\u30af\u30bb\u30b9<\/h2>\n<p>\u30eb\u30fc\u30c8\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u4f5c\u6210\u6642\u306b\u30b9\u30c8\u30a2\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u8a18\u8ff0\u3057\u3066\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u6e21\u3059\u5b9a\u7fa9\u3092\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">new Vue({\r\n  \/\/\u3044\u308d\u3044\u308d\u306a\u51e6\u7406\r\n  store\r\n})<\/pre>\n<p>\u3053\u306estore\u30aa\u30d7\u30b7\u30e7\u30f3\u306b\u306f\u30b9\u30c8\u30a2\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304c\u5165\u3063\u3066\u3044\u308b\u306e\u3067\u30b9\u30c6\u30fc\u30c8\u306e\u53d6\u5f97\u3084\u30a2\u30af\u30b7\u30e7\u30f3\u306e\u5b9f\u884c\u7b49\u30b9\u30c8\u30a2\u306e\u64cd\u4f5c\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<h2>\u30d8\u30eb\u30d1\u30fc\u95a2\u6570\u306b\u3088\u308b\u30a2\u30af\u30bb\u30b9<\/h2>\n<p>\u4e0b\u8a18\u306e\u7a2e\u985e\u304c\u3042\u308a\u307e\u3059\u3002<span style=\"color: #ff0000;\"><strong>\u3053\u308c\u3089\u306e\u30d8\u30eb\u30d1\u30fc\u95a2\u6570\u3067\u30b9\u30c6\u30fc\u30c8\u3001\u30b2\u30c3\u30bf\u30fc\u3001\u30df\u30e5\u30c6\u30fc\u30b7\u30e7\u30f3\u3001\u30a2\u30af\u30b7\u30e7\u30f3\u3092\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u7b97\u51fa\u30d7\u30ed\u30d1\u30c6\u30a3\u3084\u30e1\u30bd\u30c3\u30c9\u306b\u7d50\u3073\u3064\u3051\u308b\u3053\u3068\u304c\u53ef\u80fd<\/strong><\/span>\u3067\u3059\u3002<\/p>\n<ul>\n<li>mapState<\/li>\n<li>mapGetters<\/li>\n<li>mapMutations<\/li>\n<li>mapActions<\/li>\n<\/ul>\n<h3>\u30e1\u30ea\u30c3\u30c8<\/h3>\n<ul>\n<li>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5074\u304b\u3089\u7c21\u5358\u306b\u30b9\u30c8\u30a2\u3092\u4f7f\u3046\u3053\u3068\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/li>\n<\/ul>\n<h3>\u69cb\u6587<\/h3>\n<h4>\u901a\u5e38\u306e\u66f8\u304d\u65b9<\/h4>\n<pre class=\"lang:default decode:true\">&lt;script&gt;\r\nimport {mapState,mapMutations} from 'vuex'\r\n\r\nexport default{\r\n\r\n  \/\/$store.state.data1\u3092this.data1\u306b\u7d50\u3073\u3064\u3051\u307e\u3059\u3002\r\n  computed:mapState([\r\n    'data1'\r\n  ])\r\n\r\n  \/\/$store.commit('\u30df\u30e5\u30c6\u30fc\u30b7\u30e7\u30f3\u540d',\u30da\u30a4\u30ed\u30fc\u30c9)\u3092this.\u30df\u30e5\u30c6\u30fc\u30b7\u30e7\u30f3\u540d(\u30da\u30a4\u30ed\u30fc\u30c9)\u306b\u7d50\u3073\u3064\u3051\u307e\u3059\u3002\r\n  methods:mapMutations([\r\n    '\u30df\u30e5\u30c6\u30fc\u30b7\u30e7\u30f3\u540d'\r\n  ])\r\n\r\n}\r\n\r\n\r\n&lt;\/script&gt;\r\n<\/pre>\n<p>\u305f\u3060\u3001\u3053\u308c\u3060\u3068computed\u306b\u30b9\u30c8\u30a2\u306e\u30b9\u30c6\u30fc\u30c8\u304c\u7d10\u3065\u3044\u3066\u3057\u307e\u3044\u901a\u5e38\u306e\u7b97\u51fa\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u5b9a\u7fa9\u3059\u308b\u5834\u6240\u304c\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<h4>\u901a\u5e38\u306e\u7b97\u51fa\u30d7\u30ed\u30d1\u30c6\u30a3\u3068\u30d8\u30eb\u30d1\u30fc\u95a2\u6570\u3092\u5171\u5b58\u3055\u305b\u308b\u8a18\u8ff0\u65b9\u6cd5<\/h4>\n<p><span style=\"color: #ff0000;\"><strong>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u30b9\u30d7\u30ec\u30c3\u30c9\u6f14\u7b97\u5b50\uff08...\uff09<\/strong><\/span>\u3092\u4f7f\u3048\u3070\u5171\u5b58\u3055\u305b\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true  \">&lt;script&gt;\r\nimport {mapState,mapMutations} from 'vuex'\r\n\r\nexport default{\r\n\r\n  \/\/$store.state.data1\u3092this.data1\u306b\u7d50\u3073\u3064\u3051\u307e\u3059\u3002\r\n  computed:\r\n\r\n   \u901a\u5e38\u306e\u7b97\u51fa\u30d7\u30ed\u30d1\u30c6\u30a3\u540d () {\r\n      return \u8a08\u7b97\r\n    }, \r\n\r\n    ...mapState([\r\n      'data1'\r\n    ])\r\n\r\n}\r\n\r\n\r\n&lt;\/script&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304b\u3089Vuex\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u306b\u306f\u4e8c\u3064\u306e\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002 this.$store\u306b\u3088\u308a\u76f4\u63a5\u4f7f\u3046\u65b9\u6cd5 Vuex\u304c\u63d0\u4f9b\u3057\u3066\u3044\u308b\u30d8\u30eb\u30d1\u30fc\u95a2\u6570\u3092\u4f7f\u7528\u3059\u308b\u65b9\u6cd5 this.$store\u306b\u3088\u308b\u30a2\u30af\u30bb\u30b9 \u30eb\u30fc\u30c8\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8 [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[60],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/10053"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10053"}],"version-history":[{"count":5,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/10053\/revisions"}],"predecessor-version":[{"id":20627,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/10053\/revisions\/20627"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10053"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}