{"id":7622,"date":"2020-08-03T15:00:45","date_gmt":"2020-08-03T06:00:45","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=7622"},"modified":"2020-10-04T18:03:15","modified_gmt":"2020-10-04T09:03:15","slug":"vue%e3%81%ae%e5%ae%9a%e7%95%aa%e3%82%a8%e3%83%a9%e3%83%bc%e3%80%8cavoid-mutating-a-prop-directly-%e3%80%8d%e3%81%ae%e5%8e%9f%e5%9b%a0%e3%81%a8%e5%af%be%e5%87%a6%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=7622","title":{"rendered":"Vue\u306e\u5b9a\u756a\u30a8\u30e9\u30fc\u300cAvoid mutating a prop directly&#8230;\u300d\u306e\u539f\u56e0\u3068\u5bfe\u51e6\u65b9\u6cd5"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001<code>Laravel<\/code>\u3082\u305d\u3046\u3067\u3059\u304c\u300c\u3061\u3087\u3063\u3068\u3060\u3051\u4f7f\u3063\u3066\u307f\u308b\u304b\ud83d\ude0a\u300d\u306e\u7d50\u679c\u3001\u3082\u306f\u3084\u624b\u653e\u305b\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3063\u305f<code>JavaScript<\/code>\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u304c<code>Vue.js<\/code>\u3067\u3059\u3002<\/p>\n<p><code>Vue.js<\/code>\u306f\u4ed6\u306e\u8a18\u4e8b\u3082\u516c\u958b\u3057\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u3088\u304f\u8003\u3048\u305f\u3089\u3001<\/p>\n<ul>\n<li>\u307e\u3060\u8a18\u4e8b\u306b\u3057\u3066\u306a\u304b\u3063\u305f\ud83d\ude02<\/li>\n<li>\u5b9a\u756a\u3068\u8a00\u3048\u3070\u5b9a\u756a\ud83d\ude25<\/li>\n<li>\u3061\u3087\u3063\u3068\u3060\u3051\u3084\u3063\u304b\u3044\ud83d\ude2b<\/li>\n<\/ul>\n<p>\u306a\u5185\u5bb9\u304c\u3042\u308b\u3053\u3068\u306b\u6c17\u304c\u3064\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u308c\u306f\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<p><strong style=\"font-size: 35px;\">Avoid mutating a prop directly &#8230;\uff08\u76f4\u63a5\u30d7\u30ed\u30d1\u30c6\u30a3\u5909\u66f4\u3057\u306a\u3044\u3067\uff09<\/strong><\/p>\n<p>\u30a8\u30e9\u30fc\u3067\u3059\u3002\u5168\u6587\u306f\u3053\u3061\u3089\u3002<\/p>\n<p style=\"line-height: 1.3em; color: #555;\">[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop&#8217;s value.<\/p>\n<p><strong>\u3010\u8d85\u610f\u8a33\u3011<\/strong>\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u4e2d\u8eab\u3092\u76f4\u63a5\u5909\u66f4\u3059\u308b\u3068\u3001\u3042\u3068\u3067\u4e0a\u66f8\u304d\u3055\u308c\u3061\u3083\u3046\u304b\u3082\u3057\u308c\u306a\u3044\u304b\u3089\u3001\u3084\u3081\u3066\u306d\ud83d\ude2b<\/p>\n<p>\u305d\u3053\u3067\u2757<\/p>\n<p>\u4eca\u56de\u306f\u300c<strong>Avoid mutating a prop directly<\/strong>\u300d\u30a8\u30e9\u30fc\u306e\u539f\u56e0\u3068\u5bfe\u51e6\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u7686\u3055\u3093\u306e\u304a\u5f79\u306b\u305f\u3066\u308b\u3068\u5b09\u3057\u3044\u3067\u3059\ud83d\ude0a\u2728<\/p>\n<p>\u203b\u3061\u306a\u307f\u306b\u3001\u6b63\u78ba\u306b\u8a00\u3046\u3068\u300c<strong>Avoid mutating &#8230;<\/strong>\u300d\u306f\u30a8\u30e9\u30fc\u3067\u306f\u306a\u304f\u300c\u8b66\u544a\u300d\u3067\u3059\u304c\u3001\u76f4\u611f\u7684\u306b\u5206\u304b\u308a\u3084\u3059\u3044\u3068\u601d\u3044\u307e\u3057\u305f\u306e\u3067\u3001\u3053\u306e\u8a18\u4e8b\u5185\u3067\u306f\u300c\u30a8\u30e9\u30fc\u300d\u3068\u547c\u3076\u3053\u3068\u306b\u3057\u307e\u3059\u3002<\/p>\n<p><strong>\u3010\u8ffd\u8a18\uff1a2020.10.04\u3011<\/strong>\u5909\u6570\u3092\u540c\u671f\u3059\u308b\u65b9\u6cd5\u3068\u3057\u3066<code>.sync<\/code>\u3092\u4f7f\u3046\u65b9\u6cd5\u3092\u8ffd\u52a0\u3057\u307e\u3057\u305f\u3002<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6068 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_12.png\" alt=\"\" width=\"226\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_12.png 226w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_12-212x300.png 212w\" sizes=\"auto, (max-width: 226px) 100vw, 226px\" \/>\u300cLED\u304c\u5207\u308c\u305f\u3068\u601d\u3063\u305f\u3089<br \/>\n\u672c\u4f53\u3067\u306f\u306a\u304f\u4ed8\u5c5e\u306e\u90e8\u54c1\u304c\u5bff\u547d\u3089\u3057\u3044\u3067\u3059\u3002<br \/>\n\u30fb\u30fb\u30fb\u3044\u3084\u3001\u305d\u308c\u3063\u3066\ud83d\ude2d\u300d<\/p>\n<p><strong>\u958b\u767a\u74b0\u5883\uff1a<\/strong> Vue 2.6.11\uff08\u306a\u304a\u3001<code>CDN<\/code>\u3067\u306f\u30a8\u30e9\u30fc\u8868\u793a\u3055\u308c\u306a\u304b\u3063\u305f\u306e\u3067\u3001\u5b9f\u969b\u306b\u306f<code>npm<\/code>\u304b\u3089\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u305f\u3082\u306e\u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\uff09<\/p>\n<h1>\u3069\u3093\u306a\u3068\u304d\u306b\u30a8\u30e9\u30fc\u304c\u8868\u793a\u3055\u308c\u308b\u304b<\/h1>\n<p>\u203b\u3082\u3057\u300c<strong>\u539f\u56e0\u3068\u304b\u306f\u3044\u3044\u304b\u3089\u89e3\u6c7a\u6cd5\u3092\u2757<\/strong>\u300d\u3068\u3044\u3046\u5834\u5408\u306f<a href=\"#solution\">\u3053\u3061\u3089<\/a><\/p>\n<p><code>Vue<\/code>\u306e\u4fbf\u5229\u306a\u6a5f\u80fd\u306e\uff11\u3064\u306b\u300c\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u300d\u304c\u3042\u308a\u3001\u3053\u308c\u3092<strong>\u300c\u4f7f\u3044\u307e\u308f\u3057\u300d\u3059\u308b\u3053\u3068\u3067\u4f55\u5ea6\u3082\u540c\u3058\u30b3\u30fc\u30c9\u3092\u66f8\u304b\u306a\u304f\u3066\u6e08\u3093\u3060\u308a\u3057\u307e\u3059\u3002<\/strong><\/p>\n<p>\u305f\u3060\u3057\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5185\u306b\u30c7\u30fc\u30bf\u9001\u4fe1\u3059\u308b\u300c\u30d7\u30ed\u30d1\u30c6\u30a3\u300d\u3092\u3064\u304f\u308b\u5834\u5408\u306b\u306f\u3001\u4eca\u56de\u30c6\u30fc\u30de\u306e\u300c<strong>Avoid mutating &#8230;<\/strong>\u300d\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u5b9f\u969b\u306e\u4f8b\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>&lt;!-- \u6ce8\u610f\uff1a\u3053\u306e\u30b3\u30fc\u30c9\u306f\u6b63\u3057\u304f\u3042\u308a\u307e\u305b\u3093 --&gt;\r\n&lt;html&gt;\r\n&lt;body&gt;\r\n    &lt;div id=\"app\"&gt;\r\n        &lt;!-- \u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8 --&gt;\r\n        <strong>&lt;v-message :message=\"message\"&gt;&lt;\/v-message&gt;<\/strong>\r\n    &lt;\/div&gt;\r\n    &lt;script src=\"https:\/\/cdn.jsdelivr.net\/npm\/vue@2.6.11\"&gt;&lt;\/script&gt;\r\n    &lt;script&gt;\r\n\r\n        \/\/ \u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u8868\u793a\u3059\u308b\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\r\n        <strong>Vue.component('v-message', {<\/strong>\r\n<strong>            props: ['message'],<\/strong>\r\n<strong>            template: '&lt;div v-text=\"message\"&gt;&lt;\/div&gt;',<\/strong>\r\n<strong>            mounted() {<\/strong>\r\n\r\n<strong>                this.message = '\u66f8\u304d\u63db\u3048\u305f\u30c6\u30ad\u30b9\u30c8\u3067\u3059';<\/strong>\r\n\r\n<strong>            }<\/strong>\r\n<strong>        });<\/strong>\r\n\r\n        new Vue({\r\n            el: '#app',\r\n            data: {\r\n                message: '\u5143\u306e\u30c6\u30ad\u30b9\u30c8\u3067\u3059'\r\n            }\r\n        });\r\n\r\n    &lt;\/script&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\u3053\u306e\u4e2d\u3067\u306f\u3001<code>v-message<\/code>\u3068\u3044\u3046\u30c6\u30ad\u30b9\u30c8\u3092\u8868\u793a\u3059\u308b\u3060\u3051\u306e\u30b7\u30f3\u30d7\u30eb\u306a\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u3064\u304f\u308a\u3001\u547c\u3073\u51fa\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305f\u3060\u3057\u3001\u8868\u793a\u3059\u308b\u30c6\u30ad\u30b9\u30c8\u306f<code>message<\/code>\u3068\u3044\u3046\u30d7\u30ed\u30d1\u30c6\u30a3\u304b\u3089\u53d6\u5f97\u3057\u3066\u3044\u3066\u3001\u3055\u3089\u306b\u8aad\u307f\u8fbc\u307f\u304c\u5b8c\u4e86\u3059\u308b\u3068\u3059\u3050\u306b\u3001\u4e2d\u8eab\u3092\u5909\u66f4\u3057\u3066\u3044\u308b\u3053\u3068\u306b\u6ce8\u76ee\u3057\u3066\u304f\u3060\u3055\u3044\u3002\uff08<code>mounted()<\/code>\u306e\u90e8\u5206\u3067\u3059\u306d\uff09<\/p>\n<p>\u3053\u308c\u3092\u5b9f\u884c\u3059\u308b\u3068\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7623\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/vue_avoid_mutating_1.png\" alt=\"\" width=\"197\" height=\"43\" \/><\/p>\n<p>\u305f\u3060\u3001\u5b9f\u306f\u3053\u308c\u3060\u3051\u3067\u306f\u4f55\u306e\u554f\u984c\u3082\u767a\u751f\u3057\u307e\u305b\u3093\u3002<\/p>\n<p>\u306a\u305c\u306a\u3089\u3001\u3053\u306e\u30b3\u30fc\u30c9\u3067\u306f\u3001\u305d\u306e\u5f8c\u3001<strong>\u518d\u63cf\u753b\u3059\u308b\u3053\u3068\u304c\u306a\u3044\u304b\u3089\u3067\u3059\u3002<\/strong><\/p>\n<p>\u3067\u306f\u3001\u30a8\u30e9\u30fc\u3092\u767a\u751f\u3055\u305b\u308b\u305f\u3081\u306b<code>v-model<\/code>\u3092\u8a2d\u5b9a\u3057\u305f\u5165\u529b\u30dc\u30c3\u30af\u30b9\u3092\u8ffd\u52a0\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>&lt;!-- \u6ce8\u610f\uff1a\u3053\u306e\u30b3\u30fc\u30c9\u306f\u6b63\u3057\u304f\u3042\u308a\u307e\u305b\u3093 --&gt;\r\n&lt;html&gt;\r\n&lt;body&gt;\r\n    &lt;div id=\"app\"&gt;\r\n        &lt;!-- \u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8 --&gt;\r\n        &lt;v-message :message=\"message\"&gt;&lt;\/v-message&gt;\r\n        &lt;!-- \ud83d\udc47 \u518d\u8868\u793a\u3055\u305b\u308b\u305f\u3081\u306e\u5165\u529b\u30dc\u30c3\u30af\u30b9\u3092\u8ffd\u52a0 --&gt;\r\n        <strong>&lt;input type=\"text\" v-model=\"text\"&gt;<\/strong>\r\n    &lt;\/div&gt;\r\n    &lt;script src=\"https:\/\/cdn.jsdelivr.net\/npm\/vue@2.6.11\"&gt;&lt;\/script&gt;\r\n    &lt;script&gt;\r\n\r\n        \/\/ \u7701\u7565\r\n\r\n        new Vue({\r\n            el: '#app',\r\n            data: {\r\n                message: '\u5143\u306e\u30c6\u30ad\u30b9\u30c8\u3067\u3059',\r\n                <strong>text: '' \/\/ \ud83d\udc48 v-model\u306e\u305f\u3081\u306e\u5909\u6570\u3092\u8ffd\u52a0<\/strong>\r\n            }\r\n        });\r\n\r\n    &lt;\/script&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\u3064\u307e\u308a\u3001<code>v-model<\/code>\u3067\u5909\u6570\u3092\u30d0\u30a4\u30f3\u30c7\u30a3\u30f3\u30b0\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u5165\u529b\u304c\u3042\u308b\u5ea6\u306b\u518d\u63cf\u753b\u304c\u5b9f\u884c\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001\u5b9f\u969b\u306b\u30d6\u30e9\u30a6\u30b6\u3067\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br \/>\n\u30da\u30fc\u30b8\u3092\u8868\u793a\u3057\u305f\u76f4\u5f8c\u306f\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7625\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/vue_avoid_mutating_2.png\" alt=\"\" width=\"211\" height=\"66\" \/><\/p>\n<p>\u3057\u304b\u3057\u3001\u3053\u306e\u72b6\u614b\u3067\u5165\u529b\u30dc\u30c3\u30af\u30b9\u3067\u4f55\u304b\u30c6\u30ad\u30b9\u30c8\u3092\u5165\u529b\u3057\u3066\u307f\u307e\u3059\u3002<br \/>\n\u3059\u308b\u3068\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7626\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/vue_avoid_mutating_3.png\" alt=\"\" width=\"207\" height=\"64\" \/><\/p>\n<p>\u306f\u3044\u2757<\/p>\n<p>\u305b\u3063\u304b\u304f\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5185\u90e8\u3067\u66f8\u304d\u63db\u3048\u305f\u30c6\u30ad\u30b9\u30c8\u304c\u3001<strong>\u4f55\u3082\u3057\u3066\u3044\u306a\u3044\u306e\u306b\u5143\u306e\u30c6\u30ad\u30b9\u30c8\u306b\u623b\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/strong><\/p>\n<p>\u3053\u308c\u304c\u3001\u300c<strong>Avoid mutating &#8230;<\/strong>\u300d\u30a8\u30e9\u30fc\u304c\u8b66\u544a\u3057\u3066\u3044\u308b\u7406\u7531\u3067\u3059\u3002<\/p>\n<h1>\u539f\u56e0\u306f\u4f55\u306a\u306e\u304b\uff1f<\/h1>\n<p>\u3067\u306f\u3001\u306a\u305c\u3053\u3093\u306a\u3053\u3068\u304c\u767a\u751f\u3059\u308b\u306e\u304b\u3067\u3059\u304c\u3001\u30b7\u30f3\u30d7\u30eb\u306b\u8a00\u3046\u3068\u3001<\/p>\n<p><strong style=\"font-size: 35px;\">\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5185\u3067\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u5909\u66f4\u3057\u3066\u3082\u3001\u547c\u3073\u51fa\u3057\u5143\u306b\u306f\u901a\u77e5\u3055\u308c\u306a\u3044<\/strong><\/p>\n<p>\u304b\u3089\u3067\u3059\u3002<\/p>\n<p><code>Vue<\/code>\u306b\u306f\u300c\u30c4\u30fc\u30fb\u30a6\u30a7\u30a4\u30fb\u30d0\u30a4\u30f3\u30c7\u30a3\u30f3\u30b0\u300d\u3068\u3044\u3063\u3066\u3001\u4ee5\u4e0b\u306e\u4fbf\u5229\u306a\u7279\u5fb4\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>Vue\u5909\u6570\u304c\u30d7\u30ed\u30b0\u30e9\u30e0\u4e0a\u3067\u5909\u66f4\u306b\u306a\u3063\u305f\u3089\u3001v-model\u3092\u901a\u3057\u3066\u5165\u529b\u30dc\u30c3\u30af\u30b9\u306e\u4e2d\u8eab\u3082\u5909\u66f4\u306b\u306a\u308b<\/li>\n<li>\u9006\u306b\u3001\u5165\u529b\u30dc\u30c3\u30af\u30b9\u304c\u5909\u66f4\u306b\u306a\u3063\u305f\u3089Vue\u5909\u6570\u3082\u540c\u3058\u5024\u306b\u5909\u66f4\u306b\u306a\u308b<\/li>\n<\/ul>\n<p>\u3057\u304b\u3057\u3001<strong>\u3053\u308c\u306f\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u9593\u3067\u306f\u6210\u7acb\u3057\u307e\u305b\u3093\u3002<\/strong><\/p>\n<p>\u3064\u307e\u308a\u3001<strong>\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u5024\u304c\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5185\u3067\u5909\u66f4\u3055\u308c\u3066\u3082\u3001\u5143\u30c7\u30fc\u30bf\u306f\u540c\u3058\u307e\u307e\u3067\u5909\u66f4\u3055\u308c\u306a\u3044<\/strong>\u306e\u3067\u3001\u518d\u63cf\u753b\u3055\u308c\u308b\u3068\u5143\u3005\u306e\u8868\u793a\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u3068\u3044\u3046\u308f\u3051\u3067\u3059\u3002<\/p>\n<p>\u56f3\u3067\u898b\u308b\u3068\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7627\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/vue_avoid_mutating_4.png\" alt=\"\" width=\"570\" height=\"404\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/vue_avoid_mutating_4.png 570w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/vue_avoid_mutating_4-300x213.png 300w\" sizes=\"auto, (max-width: 570px) 100vw, 570px\" \/><\/p>\n<p>\u203b\u3053\u306e\u305f\u3081\u3001\u547c\u3073\u51fa\u3057\u5143\u306e\u30c7\u30fc\u30bf\u304c\u5909\u66f4\u306b\u306a\u3063\u305f\u5834\u5408\u306f\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5185\u3067\u306f\u6700\u65b0\u30c7\u30fc\u30bf\u3067\u8868\u793a\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h1 id=\"solution\">\u300c<strong>Avoid mutating &#8230;<\/strong>\u300d\u30a8\u30e9\u30fc\u306e\u5bfe\u51e6\u65b9\u6cd5\u306f\uff1f<\/h1>\n<p>\u3067\u306f\u3001\u300c<strong>Avoid mutating<\/strong>\u300d\u30a8\u30e9\u30fc\u3092\u56de\u907f\u3059\u308b\u306b\u306f\u3069\u3046\u3059\u308c\u3070\u3044\u3044\u304b\u3067\u3059\u304c\u3001\u9805\u76ee\u304c\uff12\u3064\u3042\u308b\u306e\u3067\u3072\u3068\u3064\u305a\u3064\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2>\u30d7\u30ed\u30d1\u30c6\u30a3\u306f\u5225\u306e\u5909\u6570\u3067\u7ba1\u7406\u3059\u308b<\/h2>\n<p>\u7d50\u5c40\u306e\u3068\u3053\u308d\u3001\u30d7\u30ed\u30d1\u30c6\u30a3\u306f\u72b6\u6cc1\u306b\u3088\u3063\u3066\u52dd\u624b\u306b\u66f8\u304d\u63db\u3048\u3089\u308c\u3066\u3057\u307e\u3046\u53ef\u80fd\u6027\u304c\u3042\u308b\u3068\u3044\u3046\u306e\u304c\u539f\u56e0\u3067\u3059\u306e\u3067\u3001\u3053\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u4e2d\u8eab\u3092<strong>data\u5909\u6570<\/strong>\u3068\u3057\u3066\u7ba1\u7406\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre>Vue.component('v-message', {\r\n    props: ['message'],\r\n    <strong>data() {<\/strong>\r\n<strong>        return {<\/strong>\r\n<strong>            internalMessage: '' \/\/ \u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5185\u90e8\u3060\u3051\u3067\u4f7f\u3046\u30e1\u30c3\u30bb\u30fc\u30b8\u7528\u5909\u6570<\/strong>\r\n<strong>        }<\/strong>\r\n<strong>    },<\/strong>\r\n    template: '&lt;div <strong>v-text=\"internalMessage\"&gt;<\/strong>&lt;\/div&gt;',\r\n    <strong>watch: {<\/strong>\r\n<strong>        message: { \/\/ \u5916\u304b\u3089\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u4e2d\u8eab\u304c\u5909\u66f4\u306b\u306a\u3063\u305f\u3089\u5b9f\u884c\u3055\u308c\u308b<\/strong>\r\n<strong>            immediate: true,<\/strong>\r\n<strong>            handler(value) {<\/strong>\r\n\r\n<strong>                this.internalMessage = value;<\/strong>\r\n\r\n<strong>            }<\/strong>\r\n<strong>        }<\/strong>\r\n<strong>    }<\/strong>\r\n});<\/pre>\n<p>\u3053\u306e\u4e2d\u3067\u3084\u3063\u3066\u3044\u308b\u306e\u306f\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<p><strong>data\u5909\u6570\u306e\u8a2d\u5b9a<\/strong><\/p>\n<p>\u307e\u305a<code>data<\/code>\u5909\u6570\u306b<code>internalMessage<\/code>\u3092\u767b\u9332\u3092\u3057\u3001\u4eca\u5f8c\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u4e2d\u3067\u30e1\u30c3\u30bb\u30fc\u30b8\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u5834\u5408\u306f\u3001\u3053\u306e\u5909\u6570\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\uff08\u305d\u306e\u305f\u3081\u3001<code>v-text<\/code>\u3082<code>internalMessage<\/code>\u306b\u5909\u66f4\u3057\u3066\u3044\u307e\u3059\uff09<\/p>\n<p>\u203b\u306a\u304a\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5185\u306e<code>data<\/code>\u306f\u95a2\u6570\u3067\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u306e\u3067\u3054\u6ce8\u610f\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><strong>\u30a6\u30a9\u30c3\u30c1\u30e3\u30fc\u306e\u8a2d\u5b9a<\/strong><\/p>\n<p><code>Vue<\/code>\u306b\u306f\u300c<strong>\u30a6\u30a9\u30c3\u30c1\u30e3\u30fc<\/strong>\u300d\u3068\u547c\u3070\u308c\u308b<strong>\u30c7\u30fc\u30bf\u306e\u4e2d\u8eab\u304c\u5909\u66f4\u306b\u306a\u3063\u305f\u3089\u5b9f\u884c\u3055\u308c\u308b<\/strong>\u6a5f\u80fd\u304c\u3064\u3044\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u306a\u305c\u4eca\u56de\u30a6\u30a9\u30c3\u30c1\u30e3\u30fc\u3092\u4f7f\u3063\u3066\u3044\u308b\u304b\u3068\u3044\u3046\u3068\u3001\u4ee5\u4e0b\uff12\u70b9\u306b\u5bfe\u5fdc\u3059\u308b\u305f\u3081\u3067\u3059\u3002<\/p>\n<ul>\n<li>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304c\u8d77\u52d5\u3055\u308c\u305f\u3068\u304d\u306b\u30d7\u30ed\u30d1\u30c6\u30a3\u3092<code>internalMessage<\/code>\u3078\u683c\u7d0d\u3059\u308b\uff08\u203b\uff11\uff09<\/li>\n<li>\u305d\u306e\u5f8c\u3001\u5916\u304b\u3089\u30d7\u30ed\u30d1\u30c6\u30a3\u304c\u5909\u66f4\u306b\u306a\u3063\u3066\u3082<code>internalMessage<\/code>\u3082\u5909\u66f4\u3059\u308b\u3002<\/li>\n<\/ul>\n<p><strong>\u203b\uff11<\/strong>\uff1a <code>immediate<\/code>\u3092<code>true<\/code>\u306b\u3057\u3066\u3044\u308b\u306e\u3067\u5373\u6642\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002<\/p>\n<h2>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304b\u3089\u5916\u3078\u30c7\u30fc\u30bf\u3092\u901a\u77e5\u3059\u308b\u306b\u306f<\/h2>\n<p><code><strong>Vue<\/strong><\/code><strong>\u3067\u306f\u3001<code>JavaScript<\/code>\u304c\u901a\u5e38\u4f7f\u3063\u3066\u3044\u308b<code>change<\/code>\u3084<code>input<\/code>\u306a\u3069\u306e\u30a4\u30d9\u30f3\u30c8\u306e\u4ed6\u306b\u81ea\u5206\u3067\u597d\u304d\u306a\u30a4\u30d9\u30f3\u30c8\u3092\u3064\u304f\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/strong>\u305d\u306e\u305f\u3081\u3001\u3053\u306e\u6a5f\u80fd\u3092\u5229\u7528\u3057\u3066\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u300c\u5916\u300d\u3078\u30c7\u30fc\u30bf\u3092\u9001\u4fe1\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001\u4eca\u56de\u306f\u5909\u6570\u540d\u304c<code>message<\/code>\u306a\u306e\u3067\u3001\u300c<strong>change-message<\/strong>\u300d\u3068\u3044\u3046\u30a4\u30d9\u30f3\u30c8\u3092\u72ec\u81ea\u306b\u4f5c\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u307e\u305a\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5074\u3067\u3059\u3002<\/p>\n<pre>Vue.component('v-message', {\r\n    props: ['message'],\r\n    data() {\r\n        return {\r\n            internalMessage: '' \/\/ \u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5185\u90e8\u3060\u3051\u3067\u4f7f\u3046\u30e1\u30c3\u30bb\u30fc\u30b8\u7528\u5909\u6570\r\n        }\r\n    },\r\n    <strong>methods: {<\/strong>\r\n<strong>        changeMessage() {<\/strong>\r\n\r\n<strong>            this.internalMessage = '\u66f8\u304d\u63db\u3048\u305f\u30c6\u30ad\u30b9\u30c8\u3067\u3059';<\/strong>\r\n<strong>            this.$emit('change-message', this.internalMessage); \/\/ \ud83d\udc48 \u72ec\u81ea\u30a4\u30d9\u30f3\u30c8<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n<strong>    },<\/strong>\r\n    template: '&lt;div&gt;' +\r\n        '&lt;div v-text=\"internalMessage\"&gt;&lt;\/div&gt;'+\r\n        '<strong>&lt;button @click=\"changeMessage\"&gt;\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u66f8\u304d\u63db\u3048\u308b&lt;\/button&gt;<\/strong>'+\r\n        '&lt;\/div&gt;',\r\n    watch: {\r\n        message: { \/\/ \u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u4e2d\u8eab\u304c\u5909\u66f4\u306b\u306a\u3063\u305f\u3089\u5b9f\u884c\u3055\u308c\u308b\r\n            immediate: true,\r\n            handler(value) {\r\n\r\n                this.internalMessage = value;\r\n\r\n            }\r\n        }\r\n    }\r\n});<\/pre>\n<p>\u3053\u3053\u3067\u8ffd\u52a0\u3057\u305f\u306e\u304c\u3001<code>changeMessage()<\/code>\u30e1\u30bd\u30c3\u30c9\u3067\u3001\u300c<strong>\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u66f8\u304d\u63db\u3048\u308b<\/strong>\u300d\u3068\u3044\u3046\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3057\u305f\u3068\u304d\u306b\u5b9f\u884c\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u6ce8\u76ee\u3057\u3066\u3044\u305f\u3060\u304d\u305f\u3044\u306e\u304c\u3001<code>this.$emit()<\/code>\u306e\u90e8\u5206\u3067\u3059\u3002<\/p>\n<p>\u3053\u3053\u304c\u72ec\u81ea\u30a4\u30d9\u30f3\u30c8\u3092\u547c\u3073\u51fa\u3057\u3066\u3044\u308b\u3068\u3053\u308d\u3067\u3001\u7b2c\uff11\u5f15\u6570\u304c\u30a4\u30d9\u30f3\u30c8\u306e\u540d\u524d\uff08\u72ec\u81ea\u30a4\u30d9\u30f3\u30c8\u3060\u3051\u3067\u306a\u304f<code>input<\/code>\u306a\u3069\u3082\u4f7f\u3048\u307e\u3059\uff09\u3002\u7b2c\uff12\u5f15\u6570\u304c\u9001\u4fe1\u3057\u305f\u3044\u30c7\u30fc\u30bf\u306b\u306a\u308a\u307e\u3059\u3002\uff08\u3044\u308f\u3086\u308b\u30a4\u30d9\u30f3\u30c8\u306e\u9001\u51fa\u3067\u3059\uff09<\/p>\n<p>\u305d\u3057\u3066\u3001HTML\u5074\u3067\u3059\u3002<br \/>\n\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u72ec\u81ea\u30a4\u30d9\u30f3\u30c8\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001\u4eca\u5ea6\u306f<code>Vue<\/code>\u306e\u672c\u4f53\u3067<code>onChangeMessage()<\/code>\u304c\u5b9f\u884c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>&lt;v-message :message=\"message\" <strong>@change-message=\"onChangeMessage\"<\/strong>&gt;&lt;\/v-message&gt;<\/pre>\n<p>\u3064\u307e\u308a\u3001\u6b21\u306e\u3088\u3046\u306b\u3059\u308b\u3053\u3068\u3067\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3067\u5909\u66f4\u306b\u306a\u3063\u305f\u30c7\u30fc\u30bf\u3092\u300c\u5916\u300d\u3068\u540c\u671f\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>new Vue({\r\n    el: '#app',\r\n    data: {\r\n        message: '\u5143\u306e\u30c6\u30ad\u30b9\u30c8\u3067\u3059',\r\n        text: '' \/\/ v-model\u306e\u305f\u3081\u306e\u5909\u6570\r\n    },\r\n    <strong>methods: {<\/strong>\r\n<strong>        onChangeMessage(message) {<\/strong>\r\n\r\n<strong>            this.message = message;<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n<strong>    }<\/strong>\r\n});<\/pre>\n<p>\u3067\u306f\u3001\u3053\u3053\u307e\u3067\u306e\u6d41\u308c\u3092\u30b9\u30c8\u30fc\u30ea\u30fc\u3067\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<ol>\n<li>\u5916\u304b\u3089\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u8a2d\u5b9a\u3059\u308b<\/li>\n<li>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304c\u8d77\u52d5\u3057\u305f\u3089\u3001\u30a6\u30a9\u30c3\u30c1\u30e3\u30fc\u304c\u52d5\u3044\u3066 message \u304c internalMessage \u3068\u540c\u3058\u5024\u306b\u306a\u308b<\/li>\n<li>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5185\u3067 internalMessage \u306b\u5909\u66f4\u304c\u3042\u3063\u305f\u3089 $emit \u3067\u30a4\u30d9\u30f3\u30c8\u3092\u5b9f\u884c<\/li>\n<li>\u30a4\u30d9\u30f3\u30c8\u3092\u901a\u3057\u3066\u300c\u5916\u300d\u306b\u30c7\u30fc\u30bf\u304c\u4f1d\u308f\u308a\u3001internalMessage \u3092 message \u3068\u540c\u671f\u3059\u308b<\/li>\n<\/ol>\n<p>\u306a\u304a\u3001\u898b\u305f\u76ee\u306f\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7628\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/vue_avoid_mutating_5.png\" alt=\"\" width=\"204\" height=\"89\" \/><\/p>\n<h2>v-model\u3092\u4f7f\u3046\u5834\u5408<\/h2>\n<p><code>v-model<\/code>\u3092\u4f7f\u3046\u5834\u5408\u306f\u3082\u3046\u5c11\u3057\u30b7\u30f3\u30d7\u30eb\u306b\u5b9f\u88c5\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre>&lt;html&gt;\r\n&lt;body&gt;\r\n    &lt;div id=\"app\"&gt;\r\n        &lt;!-- \u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8 --&gt;\r\n        &lt;v-message v-model=\"message\"&gt;&lt;\/v-message&gt;\r\n    &lt;\/div&gt;\r\n    &lt;script src=\"https:\/\/cdn.jsdelivr.net\/npm\/vue@2.6.11\"&gt;&lt;\/script&gt;\r\n    &lt;script&gt;\r\n\r\n        \/\/ \u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u8868\u793a\u3059\u308b\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\r\n        Vue.component('v-message', {\r\n            props: ['value'],\r\n            data() {\r\n                return {\r\n                    internalValue: '' \/\/ \u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5185\u90e8\u3060\u3051\u3067\u4f7f\u3046\u30e1\u30c3\u30bb\u30fc\u30b8\u7528\u5909\u6570\r\n                }\r\n            },\r\n            methods: {\r\n                changeValue() {\r\n\r\n                    this.internalValue = '\u66f8\u304d\u63db\u3048\u305f\u30c6\u30ad\u30b9\u30c8\u3067\u3059';\r\n                    <strong>this.$emit('input', this.internalValue);<\/strong>\r\n\r\n                }\r\n            },\r\n            template: '&lt;div&gt;' +\r\n                '&lt;div v-text=\"internalValue\"&gt;&lt;\/div&gt;'+\r\n                '&lt;button @click=\"changeValue\"&gt;\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u66f8\u304d\u63db\u3048\u308b&lt;\/button&gt;'+\r\n                '&lt;\/div&gt;',\r\n            watch: {\r\n                value: { \/\/ \u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u4e2d\u8eab\u304c\u5909\u66f4\u306b\u306a\u3063\u305f\u3089\u5b9f\u884c\u3055\u308c\u308b\r\n                    immediate: true,\r\n                    handler(value) {\r\n\r\n                        this.internalValue = value;\r\n\r\n                    }\r\n                }\r\n            }\r\n        });\r\n\r\n        new Vue({\r\n            el: '#app',\r\n            data: {\r\n                message: '\u5143\u306e\u30c6\u30ad\u30b9\u30c8\u3067\u3059'\r\n            }\r\n        });\r\n\r\n    &lt;\/script&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\u57fa\u672c\u7684\u306b\u5148\u307b\u3069\u898b\u305f\u30d7\u30ed\u30d1\u30c6\u30a3\u3068\u72ec\u81ea\u30a4\u30d9\u30f3\u30c8\u3092\u4f7f\u3063\u305f\u3082\u306e\u3068\u540c\u3058\u306a\u306e\u3067\u3059\u304c\u3001\u4eca\u56de\u306f<code>this.$emit()<\/code>\u306b<code>input<\/code>\u30a4\u30d9\u30f3\u30c8\u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001<code>v-model<\/code>\u306e\u5834\u5408\u3001<code>input<\/code>\u30a4\u30d9\u30f3\u30c8\u304c\u5b9f\u884c\u3055\u308c\u308b\u3068\u300c\u5916\u300d\u306e\u30c7\u30fc\u30bf\u3068\u3082\u540c\u671f\u3092\u3057\u3066\u304f\u308c\u308b\u306e\u3067<strong>HTML\u306b\u3082\u3001Vue\u672c\u4f53\u306b\u3082\u72ec\u81ea\u30a4\u30d9\u30f3\u30c8\u3092\u30bb\u30c3\u30c8\u3059\u308b\u5fc5\u8981\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/strong><\/p>\n<p>\u305d\u306e\u305f\u3081\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3067\u4f7f\u3046\u30d7\u30ed\u30d1\u30c6\u30a3\u304c\u3072\u3068\u3064\u3060\u3051\u306e\u5834\u5408\u306f<code>v-model<\/code>\u3067\u5b9f\u88c5\u3059\u308b\u306e\u3082\u9078\u629e\u80a2\u306e\u3072\u3068\u3064\u3060\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306f\u4ee5\u4e0a\u3067\u3059\ud83d\ude0a\u2728<\/p>\n<h2>.sync\u3092\u4f7f\u3046\u5834\u5408<\/h2>\n<p><strong>\u3010\u8ffd\u8a18\uff1a2020.10.04\u3011<\/strong><\/p>\n<p>\u5b9f\u306f\u3001<code>Vue 3<\/code>\u3067\u306f\u5225\u306e\u4f7f\u3044\u65b9\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304c\u5916\u306e\u5909\u6570\u3068\u540c\u671f\u3059\u308b\u65b9\u6cd5\u3068\u3057\u3066<code>.sync<\/code>\u3092\u4f7f\u3046\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002\uff08\u30fb\u30fb\u30fb\u3068\u3044\u3046\u304b\u4eca\u66f4\u306a\u304c\u3089\u77e5\u308a\u307e\u3057\u305f\u30fb\u30fb\u30fb\ud83d\udca6\uff09<\/p>\n<p>\u57fa\u672c\u7684\u306b\u306f\u3053\u308c\u307e\u3067\u306e\u8aac\u660e\u3068\u540c\u3058\u304f<code>$emit<\/code>\u3092\u4f7f\u3044\u307e\u3059\u304c\u3001\u3053\u3061\u3089\u306e\u65b9\u304c\u30b3\u30fc\u30c9\u304c\u5c11\u306a\u304f\u3066\u6e08\u307f\u305d\u3046\u3067\u3059\ud83d\udc4d<\/p>\n<pre>&lt;html&gt;\r\n&lt;body&gt;\r\n&lt;div id=\"app\"&gt;\r\n    {{ inputText }}\r\n    &lt;v-test <strong>:text.sync=\"inputText\"<\/strong>&gt;&lt;\/v-test&gt;\r\n&lt;\/div&gt;\r\n&lt;script src=\"https:\/\/cdn.jsdelivr.net\/npm\/vue@2.6.11\"&gt;&lt;\/script&gt;\r\n&lt;script&gt;\r\n\r\n    Vue.component('v-test', {\r\n        props: {\r\n            text: String\r\n        },\r\n        methods: {\r\n            <strong>onInput(e) {<\/strong>\r\n\r\n<strong>                this.$emit('update:text', e.target.value);<\/strong>\r\n\r\n<strong>            }<\/strong>\r\n        },\r\n        template: `\r\n            &lt;div&gt;\r\n              &lt;input :value=\"text\" <strong>@input=\"onInput($event)\"<\/strong>&gt;&lt;\/input&gt;\r\n            &lt;\/div&gt;\r\n        `\r\n    });\r\n\r\n    new Vue({\r\n        el: '#app',\r\n        data: {\r\n            inputText: '\u30c6\u30b9\u30c8'\r\n        }\r\n    });\r\n\r\n&lt;\/script&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\u3053\u306e\u4e2d\u3067\u91cd\u8981\u306a\u306e\u306f\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306eHTML\u30bf\u30b0\u306b<code>:*****.syn<\/code>\u3068\u3044\u3046\u901a\u5e38\u306e\u30d0\u30a4\u30f3\u30c7\u30a3\u30f3\u30b0\u306b<code>.sync<\/code>\u3092\u3064\u3051\u3066\u3044\u308b\u90e8\u5206\u3001\u305d\u3057\u3066\u3001\u305d\u308c\u306b\u5bfe\u5fdc\u3059\u308b<code>this.$emit('update:*****', e.target.value)<\/code>\u3092<code>input<\/code>\u30a4\u30d9\u30f3\u30c8\u3067\u5b9f\u884c\u3057\u3066\u3044\u308b\u90e8\u5206\u3067\u3059\u3002<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001\u6d41\u308c\u3068\u3057\u3066\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<ol>\n<li><code>sync<\/code>\u3092\u6307\u5b9a\u3057\u305f\u3053\u3068\u3067\u3001\u30d7\u30ed\u30d1\u30c6\u30a3\u300ctext\u300d\u3092\u76e3\u8996<\/li>\n<li>&lt;input&gt; \u30bf\u30b0\u306b\u5909\u66f4\u304c\u3042\u3063\u305f\u3089\u300conInput()\u300d\u3092\u5b9f\u884c<\/li>\n<li>\u30a4\u30d9\u30f3\u30c8\u300cupdate:text\u300d\u3092\u547c\u3073\u51fa\u3057\u5074\u3078\u9001\u308b<\/li>\n<li>\u81ea\u52d5\u3067\u5909\u6570\u3092\u540c\u671f<\/li>\n<\/ol>\n<p>\u3064\u307e\u308a\u3001\u4eca\u56de\u306e\u30b1\u30fc\u30b9\u3067\u8a00\u3046\u3068\u3001\u4ee5\u4e0b\u306e\uff12\u3064\u304c\u30da\u30a2\u306b\u306a\u3063\u3066\u52d5\u304f\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>:text.sync=&#8221;*****&#8221;<\/li>\n<li>this.$emit(&#8216;update:text&#8217;, &#8216;*****&#8217;)<\/li>\n<\/ul>\n<p>\u306a\u304a\u3001<code>Vue 3<\/code>\u304b\u3089\u306f\u3001<code>v-model:text<\/code>\u3068\u3044\u3046\u3088\u3046\u306b<code>v-model<\/code>\u304c\u62e1\u5f35\u3055\u308c\u305f\u66f8\u304d\u65b9\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<h1>\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b<\/h1>\n<p>\u4eca\u56de\u5b9f\u969b\u306b\u958b\u767a\u3057\u305f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u4e00\u5f0f\u3092\u4ee5\u4e0b\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<a  data-e-Disable-Page-Transition=\"true\" class=\"download-link\" title=\"\" href=\"https:\/\/blog.capilano-fw.com?download=7629&amp;tmstv=1777532620\" rel=\"nofollow\" id=\"download-link-7629\" data-redirect=\"false\" >\n\t\u300cAvoid mutating a prop directly...\u300d\u306e\u539f\u56e0\u3068\u5bfe\u51e6\u65b9\u6cd5<\/a>\n\n<p>\u203b <code>CDN<\/code>\u3092\u4f7f\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u5c55\u958b\u3057\u3066\u3059\u3050\u5b9f\u884c\u3067\u304d\u307e\u3059\u3088\ud83d\udc4d<\/p>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u4eca\u56de\u306f\u3001<code>Vue<\/code>\u3067\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u3064\u304f\u308b\u969b\u306b\u906d\u9047\u3059\u308b\u30a8\u30e9\u30fc\u300c<strong>Avoid mutating &#8230;<\/strong>\u300d\u306b\u3064\u3044\u3066\u307e\u3068\u3081\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u3053\u306e\u3042\u305f\u308a\u304c<code>Vue<\/code>\u306e\u300c\u30af\u30bb\u300d\u307f\u305f\u3044\u306a\u3082\u306e\u3060\u3068\u601d\u3044\u307e\u3059\u306e\u3067\u3001\u3053\u3053\u3092\u62bc\u3055\u3048\u3066\u304a\u3051\u3070<code>Vue<\/code>\u306e\u958b\u767a\u3082\u3088\u308a\u697d\u306b\u306a\u308b\uff08\u5143\u3005\u697d\u3067\u3059\u3051\u3069\u306d\u30fb\u30fb\u30fb\ud83d\ude02\uff09\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u307f\u306a\u3055\u3093\u3082\u53c2\u8003\u306b\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\u2757<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6067 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_19.png\" alt=\"\" width=\"314\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_19.png 314w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_19-294x300.png 294w\" sizes=\"auto, (max-width: 314px) 100vw, 314px\" \/>\u300c\u7121\u6027\u306b\u30b9\u30fc\u30d1\u30fc\u306b\u58f2\u3063\u3066\u308b<br \/>\n\u308f\u3089\u3073\u9905\u304c\u98df\u3079\u305f\u304f\u306a\u308b\u3068\u304d\u3063\u3066\u3042\u308a\u307e\u305b\u3093\u304b\uff1f\u300d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001Laravel\u3082\u305d\u3046\u3067\u3059\u304c\u300c\u3061\u3087\u3063\u3068\u3060\u3051\u4f7f\u3063\u3066\u307f\u308b\u304b\ud83d\ude0a\u300d\u306e\u7d50\u679c\u3001\u3082\u306f\u3084\u624b\u653e\u305b\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3063\u305fJavaScript\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u304cVue.js\u3067\u3059\u3002  &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=7622\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Vue\u306e\u5b9a\u756a\u30a8\u30e9\u30fc\u300cAvoid mutating a prop directly&#8230;\u300d\u306e\u539f\u56e0\u3068\u5bfe\u51e6\u65b9\u6cd5&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":7638,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[34],"class_list":["post-7622","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vue-js","tag-34"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/7622","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=7622"}],"version-history":[{"count":16,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/7622\/revisions"}],"predecessor-version":[{"id":7635,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/7622\/revisions\/7635"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/7638"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7622"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7622"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7622"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}