{"id":485,"date":"2018-05-09T20:52:40","date_gmt":"2018-05-09T11:52:40","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=485"},"modified":"2018-05-09T20:52:41","modified_gmt":"2018-05-09T11:52:41","slug":"vue%e3%81%ae%e3%80%8cmethods%e3%80%8d%e3%81%a8%e3%80%8ccomputed%e3%80%8d%e3%81%ae%e9%81%95%e3%81%84","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=485","title":{"rendered":"Vue\u306e\u300cmethods\u300d\u3068\u300ccomputed\u300d\u306e\u9055\u3044"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3059\u3067\u306b\u79c1\u304c\u958b\u767a\u73fe\u5834\u3067\u3082\u30ac\u30f3\u30ac\u30f3\u4f7f\u3063\u3066\u3044\u308bvue.js\u3067\u3059\u304c\u3001<a href=\"http:\/\/www.timqian.com\/star-history\/#facebook\/react&amp;angular\/angular&amp;vuejs\/vue\" target=\"_blank\" rel=\"noopener\">GitHub\u306e\u30b9\u30bf\u30fc\u5c65\u6b74<\/a>\u3067\u3082react\u3092\u8ffd\u3044\u629c\u304f\u52e2\u3044\u306b\u306a\u3063\u3066\u304d\u307e\u3057\u305f\u3002\uff082018\/5\/10\u73fe\u5728\uff09<\/p>\n<p>\u3082\u3061\u308d\u3093\u3001react\u3082\u4f9d\u7136\u3068\u3057\u3066\u4eba\u6c17\u3067\u9806\u8abf\u306b\u30b9\u30bf\u30fc\u3092\u7372\u5f97\u3057\u3066\u308b\u3088\u3046\u3067\u3059\u3051\u3069\u3001\u30e9\u30a4\u30bb\u30f3\u30b9\u554f\u984c\u304c\u767a\u751f\u3057\u3066<a href=\"https:\/\/capitalp.jp\/2017\/09\/15\/wordpress-drop-off-react\/\" target=\"_blank\" rel=\"noopener\">wordpress\u304creact\u306e\u5229\u7528\u3092\u3084\u3081\u308b\u3068\u3044\u3046\u30cb\u30e5\u30fc\u30b9<\/a>\u304c\u6d41\u308c\u3066\u305f\u308a\u3057\u3066\u3001\u4eca\u5f8c\u3053\u306e\u4eba\u6c17\u304c\u7d9a\u304f\u304b\u3069\u3046\u304b\u3061\u3087\u3063\u3068\u7591\u554f\u3060\u3063\u305f\u308a\u3057\u3066\u307e\u3059\u3002\uff08\u3066\u304b\u3001wordpress\u3063\u3066react\u4f7f\u3063\u3066\u305f\u3093\u3067\u3059\u306d\u3002\u77e5\u3089\u306a\u304b\u3063\u305f\u30fb\u30fb\u30fb\uff09<\/p>\n<h1>methods\u3068computed\u306e\u9055\u3044\u3068\u306f\u30fb\u30fb\u30fb\uff1f<\/h1>\n<p>\u3067\u3001\u305d\u3093\u306a\u3053\u3068\u3082\u3042\u3063\u3066\u30e1\u30a4\u30f3\u3067\u4f7f\u3046JS\u306f\u3084\u3063\u3071\u308a\u300cVue\u300d\u3067\u884c\u3053\u3046\u3068\u8003\u3048\u3066\u308b\u3093\u3067\u3059\u3051\u3069\u3001\u6700\u8fd1\u305d\u3093\u306aVue\u3067\u3072\u3068\u3064\u30ad\u30c1\u30f3\u3068\u7406\u89e3\u3067\u304d\u3066\u3044\u306a\u3044\u90e8\u5206\u304c\u3042\u308b\u3053\u3068\u306b\u6c17\u304c\u4ed8\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u308c\u304c\u3001<\/p>\n<p><b style=\"font-size: 35px;\">\u300cmethods\u300d\u3068\u300ccomputed\u300d\u306e\u9055\u3044<\/b><\/p>\n<p>\u3067\u3059\u3002<\/p>\n<p>\u6b63\u76f4\u306a\u3068\u3053\u308d\u3001\u3053\u308c\u307e\u3067\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u62ec\u5f27\u304c\u3064\u304f\u304b\u3064\u304b\u306a\u3044\u304b\u3001\u3050\u3089\u3044\u306b\u8003\u3048\u3066\u307e\u3057\u305f\u3002\uff08\u3042\u3068\u306f\u3001getter\u3068setter\u304ccomputed\u306b\u306f\u8a2d\u5b9a\u3067\u304d\u308b\u3068\u304b\u3067\u3059\u306d\uff09<\/p>\n<pre>&lt;!-- methods --&gt;\n&lt;div v-text=\"<b>textMethod()<\/b>\"&gt;&lt;\/div&gt;\n\n&lt;!-- computed --&gt;\n&lt;div v-text=\"<b>textComputed<\/b>\"&gt;&lt;\/div&gt;<\/pre>\n<p>\u57fa\u672c\u7684\u306b\u306f\u307b\u3068\u3093\u3069\u304a\u3093\u306a\u3058\u6319\u52d5\u306b\u306a\u308b\u3093\u3067\u3001\u3082\u3057Vue\u5185\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306amethod\u3068computed\u3092\u4f5c\u3063\u3066\u3084\u308b\u3068\u3001\u3069\u3061\u3089\u3082\u300c\u30c6\u30ad\u30b9\u30c8\u300d\u3068\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre><b>methods: {<\/b>\n<b>    textMethod: function() {<\/b>\n\n<b>        return '\u30c6\u30ad\u30b9\u30c8';<\/b>\n\n<b>    }<\/b>\n<b>},<\/b>\n<b>computed: {<\/b>\n<b>    textComputed: function() {<\/b>\n\n<b>        return '\u30c6\u30ad\u30b9\u30c8';<\/b>\n\n<b>    }<\/b>\n<b>}<\/b><\/pre>\n<p>\u3067\u3082\u3001\u8abf\u3079\u3066\u307f\u308b\u3068method\u3068computed\u306b\u306f\u5927\u304d\u306a\u9055\u3044\u304c\u3042\u308a\u307e\u3057\u305f\u3002\u305d\u308c\u306f\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<p><b style=\"font-size: 35px;\">\u30c7\u30fc\u30bf\u304c\u30ad\u30e3\u30c3\u30b7\u30e5\u3055\u308c\u308b or \u3055\u308c\u306a\u3044<\/b><\/p>\n<p>\u3067\u3059\u3002\u3064\u307e\u308a\u3001<b>computed\u306f\u5143\u30c7\u30fc\u30bf\u306e\u5909\u66f4\u304c\u3042\u3063\u305f\u6642\u70b9\u3067\u30c7\u30fc\u30bf\u304c\u4fdd\u5b58\u3055\u308c\u308b\u306e\u306b\u5bfe\u3057\u3066method\u5074\u306f\u3044\u3064\u3067\u3082\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3057\u3066\u5024\u3092\u8a08\u7b97\u3059\u308b<\/b>\u3068\u3044\u3046\u3053\u3068\u3067\u3057\u305f\u3002<\/p>\n<h1>\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9<\/h1>\n<p>\u5b9f\u969b\u306e\u4f8b\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002\uff08\u30b3\u30d4\u30da\u3060\u3051\u3067\u52d5\u304f\u306f\u305a\u3067\u3059\uff09<\/p>\n<pre>&lt;html&gt;\n&lt;body&gt;\n    &lt;div id=\"app\"&gt;\n        &lt;button type=\"button\" @click=\"show=!show\"&gt;\u8868\u793a\uff0f\u975e\u8868\u793a&lt;\/button&gt;\n        &lt;div v-if=\"show\"&gt;\n            Method: &lt;span v-text=\"nowMethod()\"&gt;&lt;\/span&gt;\n            &lt;br&gt;\n            Computed: &lt;span v-text=\"nowComputed\"&gt;&lt;\/span&gt;\n        &lt;\/div&gt;\n    &lt;\/div&gt;\n    &lt;script src=\"https:\/\/cdn.jsdelivr.net\/npm\/vue@2.5.16\/dist\/vue.min.js\"&gt;&lt;\/script&gt;\n    &lt;script&gt;\n\n        new Vue({\n            el: '#app',\n            data: {\n                show: true\n            },\n            methods: {\n                nowMethod: function() {\n\n                    return Date.now();  \/\/ \u305d\u306e\u90fd\u5ea6\u66f4\u65b0\n\n                }\n            },\n            computed: {\n                nowComputed: function() {\n\n                    return Date.now();  \/\/ \u30ad\u30e3\u30c3\u30b7\u30e5\u3055\u308c\u308b\n\n                }\n            }\n        });\n\n    &lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u3067\u3084\u3063\u3066\u308b\u3053\u3068\u306f\u3001<\/p>\n<ol>\n<li>\u4eca\u306e\u6642\u9593\u3092\u8868\u793a\u3059\u308b<\/li>\n<li>\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3057\u305f\u3089\u3001\u305d\u306e\u6642\u9593\u304c\u8868\u793a\uff0f\u975e\u8868\u793a\u306b\u306a\u308b<\/li>\n<\/ol>\n<p>\u3068\u3044\u3046\u30b7\u30f3\u30d7\u30eb\u306a\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>\u3067\u3001\u3053\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u8868\u793a\u3057\u305f\u3089\u3001\u307e\u305a\u306f\u3053\u3093\u306a\u8868\u793a\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-486\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/05\/l56-test-vue_methods_n_computed.png\" alt=\"\" width=\"238\" height=\"95\"><\/p>\n<p>\u540c\u3058\u6642\u9593\u304c\u8868\u793a\u3055\u308c\u3066\u3044\u307e\u3059\u306d\u3002\uff08\u30bf\u30a4\u30df\u30f3\u30b0\u306b\u3088\u3063\u30661\u79d2\u307b\u3069\u305a\u308c\u308b\u3053\u3068\u306f\u3042\u308a\u307e\u3059\u3051\u3069\u306d\u3002\u5ff5\u306e\u70ba\u3002\uff09<\/p>\n<p>\u3067\u306f\u3001\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u4e00\u65e6\u6642\u9593\u3092\u975e\u8868\u793a\u306b\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-487\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/05\/l56-test-vue_methods_n_computed-1.png\" alt=\"\" width=\"197\" height=\"85\"><\/p>\n<p>\u6d88\u3048\u307e\u3057\u305f\u3002<br \/>\n\u3067\u3001\u3082\u3046\u4e00\u5ea6\u30af\u30ea\u30c3\u30af\u3057\u3066\u6642\u9593\u3092\u8868\u793a\u3057\u3066\u307f\u308b\u3068\u30fb\u30fb\u30fb\u30fb\uff1f\uff1f<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-488\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/05\/l56-test-vue_methods_n_computed-2.png\" alt=\"\" width=\"607\" height=\"108\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/05\/l56-test-vue_methods_n_computed-2.png 607w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/05\/l56-test-vue_methods_n_computed-2-300x53.png 300w\" sizes=\"auto, (max-width: 607px) 100vw, 607px\" \/><\/p>\n<p>computed \u306e\u65b9\u306f\u3001\u30c7\u30fc\u30bf\u304c\u305d\u306e\u307e\u307e\u306a\u306e\u306b\u5bfe\u3057\u3066method\u306f\u3001\u6642\u9593\u304c\u66f4\u65b0\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u3064\u307e\u308a\u3001\u3053\u308c\u304c\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u6709\u7121\u3067\u3059\u306d\u3002<\/p>\n<h1>\u4f55\u306e\u305f\u3081\u306bcomputed\u304c\u3042\u308b\u306e\u304b\uff1f<\/h1>\n<p>\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u3082\u66f8\u3044\u3066\u3042\u308a\u307e\u3059\u304c\u3001\u9ad8\u901f\u5316 and \u7701\u529b\u5316\u306e\u305f\u3081\u3067\u3059\u306d\u3002<br \/>\n\u3055\u3063\u304d\u306e\u4f8b\u306e\u3088\u3046\u306b\u3001\u30c7\u30fc\u30bf\u304c\u5c11\u306a\u3044\u5834\u5408\u306f\u4f55\u306e\u554f\u984c\u3082\u306a\u3044\u3093\u3067\u3057\u3087\u3046\u3051\u3069\u3001\u3053\u308c\u304c\u4f55\u5343\u4ef6\u3001\u4f55\u4e07\u4ef6\u306e\u30c7\u30fc\u30bf\u3092\u30eb\u30fc\u30d7\u51e6\u7406\u3059\u308b\u5834\u5408\u306f\u3084\u3063\u3071\u308a\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u306a\u3044\u3068\u8868\u793a\u30b9\u30d4\u30fc\u30c9\u304c\u9045\u304f\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002\u3064\u307e\u308a\u3001\u30e6\u30fc\u30b6\u30fc\u30d3\u30ea\u30c6\u30a3\u306b\u60aa\u5f71\u97ff\u304c\u3067\u308b\u3063\u3066\u3053\u3068\u3067\u3059\u306d\u3002<\/p>\n<p>\u306a\u306e\u3067\u3001\u3082\u3057Ajax\u3092\u4f7f\u3063\u3066\u30b5\u30fc\u30d0\u30fc\u304b\u3089\u5927\u91cf\u306e\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u3066\u4e00\u89a7\u8868\u793a\u3059\u308b\u3001\u307f\u305f\u3044\u306a\u3053\u3068\u304c\u3042\u308b\u5834\u5408\u306fcomputed\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u8003\u616e\u3057\u305f\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u3044\u304f\u3079\u304d\u3067\u3059\u306d\u3002\u3055\u3059\u304cVue\u3001\u305d\u3093\u306a\u3068\u3053\u308d\u307e\u3067\u8003\u616e\u3057\u3066\u304f\u308c\u3066\u305f\u3068\u306f\uff01<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306fVue\u306e\u300cmethod\u300d\u3068\u300ccomputed\u300d\u306e\u9055\u3044\u306b\u3064\u3044\u3066\u66f8\u3044\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u305c\u3072\u307f\u306a\u3055\u3093\u3082\u300c\u30ad\u30e3\u30c3\u30b7\u30e5\u300d\u3092\u4f7f\u3063\u3066\u9ad8\u901f\u30b3\u30fc\u30c9\u3092\u5b9f\u73fe\u3057\u3066\u304f\u3060\u3055\u3044\u306d\uff01<\/p>\n<p>\u3067\u306f\u3067\u306f\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-427 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/24.png\" alt=\"\" width=\"182\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/24.png 182w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/24-171x300.png 171w\" sizes=\"auto, (max-width: 182px) 100vw, 182px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3059\u3067\u306b\u79c1\u304c\u958b\u767a\u73fe\u5834\u3067\u3082\u30ac\u30f3\u30ac\u30f3\u4f7f\u3063\u3066\u3044\u308bvue.js\u3067\u3059\u304c\u3001GitHub\u306e\u30b9\u30bf\u30fc\u5c65\u6b74\u3067\u3082react\u3092\u8ffd\u3044\u629c\u304f\u52e2\u3044\u306b\u306a\u3063\u3066\u304d\u307e\u3057\u305f\u3002\uff082018\/5\/10 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=485\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Vue\u306e\u300cmethods\u300d\u3068\u300ccomputed\u300d\u306e\u9055\u3044&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":489,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[64],"class_list":["post-485","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vue-js","tag-64"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/485","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=485"}],"version-history":[{"count":3,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/485\/revisions"}],"predecessor-version":[{"id":492,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/485\/revisions\/492"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/489"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=485"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=485"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}