
{"id":6639,"date":"2024-01-26T19:13:04","date_gmt":"2024-01-26T10:13:04","guid":{"rendered":"https:\/\/techmania.jp\/blog\/?p=6639"},"modified":"2024-01-29T11:26:05","modified_gmt":"2024-01-29T02:26:05","slug":"vue-js-composition-api","status":"publish","type":"post","link":"https:\/\/techmania.jp\/blog\/vue-js-composition-api\/","title":{"rendered":"Composition API\u3068\u306f\uff1fOptions API\u3068\u306e\u9055\u3044\u3084\u66f8\u304d\u65b9\u3092\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3067\u89e3\u8aac"},"content":{"rendered":"\n<h2 id=\"outline__1\" class=\"wp-block-heading\">Composition API\u3068\u306f\uff1f<\/h2>\n\n\n<p>Composition API\u3068\u306f\u3001Vue3\u304b\u3089\u5c0e\u5165\u3055\u308c\u305f\u65b0\u6a5f\u80fd\u3067\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u5b9f\u88c5\u3059\u308bAPI\u3092\u6307\u3057\u307e\u3059\u3002\u300c\u30ea\u30a2\u30af\u30c6\u30a3\u30d6\u306a\u5024\u3084\u305d\u308c\u306b\u95a2\u9023\u3057\u305f\u95a2\u6570\u3092\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304b\u3089\u5207\u308a\u96e2\u3057\u3066\u6271\u3048\u308b\u300d\u3068\u3044\u3046\u7279\u5fb4\u3092\u6301\u3064\u3053\u3068\u304b\u3089\u3001<strong>\u30b3\u30fc\u30c9\u306e\u518d\u5229\u7528\u6027\u3084\u4fdd\u5b88\u6027\u306e\u5411\u4e0a<\/strong>\u304c\u671f\u5f85\u3055\u308c\u3066\u3044\u307e\u3059\u3002<br \/>Vue2\u306e\u30b5\u30dd\u30fc\u30c8\u304c2023\u5e7412\u670831\u65e5\u3092\u3082\u3063\u3066\u7d42\u4e86\u3057\u305f\u305f\u3081\u3001Vue2\u304b\u3089Vue3\u3078\u306e\u79fb\u884c\u3092\u691c\u8a0e\u3057\u3066\u3044\u308b\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3082\u5897\u3048\u3066\u3044\u308b\u3068\u601d\u3044\u307e\u3059\u3002Vue3\u3078\u306e\u79fb\u884c\u306b\u4f34\u3044\u3001Composition API\u3082\u307e\u3059\u307e\u3059\u5e83\u307e\u308b\u3053\u3068\u304c\u4e88\u6e2c\u3055\u308c\u308b\u305f\u3081\u3001\u672c\u8a18\u4e8b\u304c\u5c11\u3057\u3067\u3082Composition API \u3092\u77e5\u308b\u3068\u3063\u304b\u304b\u308a\u306b\u306a\u308c\u3070\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<div class=\"questionBox\">\n<p><strong>Vue2\u3068Composition API<\/strong><\/p>\n<p>Composition API \u306f Vue3\u304b\u3089\u5c0e\u5165\u3055\u308c\u305f\u6a5f\u80fd\u3067\u3059\u304c\u3001\u5b9f\u306f Vue2 \u3067\u3082\u6271\u3046\u4e8b\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\u5f53\u8a18\u4e8b\u3067\u306fVue3\u3068\u3057\u3066\u306eComposition API\u3092\u7d39\u4ecb\u3057\u3066\u3044\u308b\u306e\u3067\u7701\u304d\u307e\u3059\u304c\u3001\u8208\u5473\u306e\u3042\u308b\u65b9\u306f\u5c0e\u5165\u65b9\u6cd5\u306b\u3064\u3044\u3066\u305c\u3072\u8abf\u3079\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<\/div>\n\n\n<div style=\"margin-top:4%;\">\n<a href=\"https:\/\/techmania.jp\/\"><\/a><p style=\"text-align:center; text-decoration:underline black; font-weight:bold;\">\u3042\u306a\u305f\u306e\u3054\u5e0c\u671b\u306b\u6cbf\u3063\u305f\u6848\u4ef6\u304c<span style=\"color: red;\">\u5fc5\u305a<\/span>\u898b\u3064\u304b\u308a\u307e\u3059<br>\u3010\u30d5\u30ea\u30fc\u30e9\u30f3\u30b9\u5411\u3051\u3011<span style=\"color: red;\">\u9ad8\u53ce\u5165<\/span>\u30fb<span style=\"color: blue;\">\u597d\u5f85\u9047<\/span>\u306e\u6848\u4ef6\u3092\u3054\u7d39\u4ecb<\/p><\/a>\n<\/div>\n<div style=\"text-align:center; margin-top:1%;\"><a href=\"https:\/\/techmania.jp\/\"><img decoding=\"async\" style=\"filter: drop-shadow(0px 0px 3px rgba(0,0,0,0.3)); width:300px;\" alt=\"TECH MANIA \u30d5\u30ea\u30fc\u30e9\u30f3\u30b9\" src=\"https:\/\/techmania.jp\/blog\/wp-content\/uploads\/2024\/01\/fl1.png\"><\/a><\/div>\n<div>\n<a href=\"https:\/\/techmania.jp\/\"><\/a><p style=\"margin-top: 1%;text-align:center; text-decoration:underline black; font-weight:bold;\">\u226b\u307e\u305a\u306f\u7c21\u5358<span style=\"color: blue;\">30<\/span>\u79d2\u3067<span style=\"color: red;\">\u7121\u6599\u304a\u554f\u3044\u5408\u308f\u305b<\/span>\u304b\u3089\u226a<\/p><\/a>\n<\/div>\n\n\n\n<h2 id=\"outline__2\" class=\"wp-block-heading\">Options API\u3068\u306e\u6bd4\u8f03<\/h2>\n\n\n<p>Options API\u306f\u3001\u524d\u30d0\u30fc\u30b8\u30e7\u30f3\u3067\u3042\u308b Vue2 \u3067\u4e00\u822c\u7684\u306b\u4f7f\u7528\u3055\u308c\u3066\u3044\u305fAPI\u3067\u3042\u308a\u3001data\u3084method\u306a\u3069\u306e\u5404\u30aa\u30d7\u30b7\u30e7\u30f3\u3054\u3068\u306b\u30ed\u30b8\u30c3\u30af\u3092\u5b9a\u7fa9\u3057\u3066\u3044\u304f\u8a18\u6cd5\u304c\u7279\u5fb4\u3067\u3059\u3002<br \/>\u5f93\u6765\u306e Options API \u306e\u554f\u984c\u70b9\u3068\u3057\u3066\u3001\u300c\u30ea\u30a2\u30af\u30c6\u30a3\u30d6\u306a\u5024\u3092 View \u304b\u3089\u5207\u308a\u96e2\u305b\u306a\u3044\u305f\u3081\u3001\u30ed\u30b8\u30c3\u30af\u3082\u5206\u96e2\u3067\u304d\u306a\u3044\u300d\u3068\u3044\u3046\u70b9\u304c\u3088\u304f\u6319\u3052\u3089\u308c\u307e\u3059\u3002<br \/>\u4e00\u65b9\u3001Composition API \u3067\u306f\u3053\u308c\u3089\u306e\u554f\u984c\u304c\u89e3\u6d88\u3055\u308c\u3001View\u3068\u30ed\u30b8\u30c3\u30af\u3092\u5206\u96e2\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002\u305d\u306e\u7d50\u679c\u3001\u53ef\u8aad\u6027\u304c\u9ad8\u307e\u308a\u30b9\u30c3\u30ad\u30ea\u3068\u3057\u305f\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<div class=\"questionBox\">\n<p><strong>Options API\u3068Composition API\u306e\u3069\u3061\u3089\u3092\u4f7f\u3048\u3070\u3044\u3044\u306e\u304b\uff1f<\/strong><\/p>\n<p>\u516c\u5f0f\u306e\u6587\u7ae0\u3092\u565b\u307f\u7815\u3044\u3066\u8f09\u305b\u308b\u3068\u300cComposition API \u306f\u5927\u898f\u6a21\u306a\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u304a\u3044\u3066\u5229\u70b9\u3092\u6d3b\u304b\u3057\u3084\u3059\u3044\u304c\u3001\u5c0f\u301c\u4e2d\u898f\u6a21\u306e\u958b\u767a\u3067\u3042\u308c\u3070 Options API \u3067\u3082\u554f\u984c\u306a\u3044\u300d\u3068\u306e\u3053\u3068\u3067\u3059\u3002<br \/>Options API \u304c\u5ec3\u6b62\u3055\u308c\u308b\u4e88\u5b9a\u306f\u4eca\u306e\u3068\u3053\u308d\u306a\u3044\u3088\u3046\u306a\u306e\u3067\u3001\u500b\u4eba\u958b\u767a\u3067\u3069\u3061\u3089\u3092\u4f7f\u3046\u304b\u8ff7\u3063\u305f\u969b\u306b\u306f\u3001\u597d\u307f\u3067\u9078\u3093\u3067\u307f\u3066\u3082\u826f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\u53c2\u8003\uff1a<a href=\"https:\/\/vuejs.org\/guide\/extras\/composition-api-faq.html\" target=\"_blank\" rel=\"noopener\">https:\/\/vuejs.org\/guide\/extras\/composition-api-faq.html<\/a><\/p>\n<\/div>\n\n\n<h2 id=\"outline__3\" class=\"wp-block-heading\">Composition API\u306e\u8a18\u8ff0\u65b9\u6cd5<\/h2>\n\n\n\n<h3 id=\"outline__3_1\" class=\"wp-block-heading\">script setup<\/h3>\n\n\n<p>Composition API\u3067\u306f\u3001\u901a\u5e38\u306e<code>&lt;script&gt;<\/code>\u3067\u306f\u306a\u304f<code>&lt;script setup&gt;<\/code>\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002 \u3053\u306e<code>&lt;script setup&gt;<\/code>\u3068\u306f\u3001Vue3.2\u3067\u6b63\u5f0f\u30ea\u30ea\u30fc\u30b9\u3055\u308c\u305fComposition API\u306e\u30b7\u30f3\u30bf\u30c3\u30af\u30b9\u30b7\u30e5\u30ac\u30fc\uff08\u7cd6\u8863\u69cb\u6587\uff09\u3067\u3059\u3002<\/p>\n<p><code>&lt;script&gt;<\/code>\u30d6\u30ed\u30c3\u30af\u306f\u3001\u30c7\u30fc\u30bf\u3084\u30e1\u30bd\u30c3\u30c9\u3092<code>export default<\/code>\u3067\u660e\u793a\u7684\u306b\u6307\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u304c\u3001<code>&lt;script setup&gt;<\/code>\u3092\u4f7f\u3046\u3068\u3001\u3053\u308c\u3089\u306e\u5b9a\u7fa9\u304c\u7c21\u6f54\u306b\u306a\u308a\u307e\u3059\u3002<!-- notionvc: 02a6bbb4-6d9f-42d4-aee4-6b7cfff5fe2d --><\/p>\n<p><!-- notionvc: 353e017c-4e14-4f02-9b24-38c40c86ed2a --><\/p>\n\n\n<pre class=\"wp-block-code\"><code>&lt;template&gt;\n &lt;div&gt;{{ count }}&lt;\/div&gt;\n &lt;button @click=\"increment\"&gt;click\uff01&lt;\/button&gt;\n&lt;\/template&gt;\n\n&lt;script setup&gt;\nlet count = 0;\nconst increment = () =&gt; count++;\n&lt;\/script&gt;<\/code><\/pre>\n\n\n<div class=\"questionBox\">\n<p><strong>SFC( Single File Component)\u306b\u3064\u3044\u3066<\/strong><\/p>\n<p>\u4e0a\u8a18\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u306e\u3088\u3046\u306btemplate\u3001script\u3001style\u3092\u4e00\u3064\u306e\u30d5\u30a1\u30a4\u30eb\u3067\u7ba1\u7406\u3057\u3066\u3044\u308b\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u3053\u3068\u3092<strong>SFC\uff08\u5358\u4e00\u30d5\u30a1\u30a4\u30eb\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\uff09<\/strong>\u3068\u8a00\u3044\u3001Vue.js\u72ec\u81ea\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306b\u306a\u308a\u307e\u3059\u3002<span style=\"font-size: revert; color: initial;\">\u3057\u304b\u3057\u3001\u3053\u306e\u307e\u307e\u3060\u3068\u5909\u6570<\/span><code>count<\/code><span style=\"font-size: revert; color: initial;\">\u306fDOM\u306b\u306f\u53cd\u6620\u3055\u308c\u305a\u3001\u30dc\u30bf\u30f3\u3092\u62bc\u3057\u3066\u3082\u6570\u5b57\u304c\u5897\u3048\u308b\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u3064\u307e\u308a<\/span><code>count<\/code><span style=\"font-size: revert; color: initial;\">\u306f<\/span><strong style=\"font-size: revert; color: initial;\">\u30ea\u30a2\u30af\u30c6\u30a3\u30d6\u306a\u5024<\/strong><span style=\"font-size: revert; color: initial;\">\u3068\u306f\u8a00\u3048\u306a\u3044\u306e\u3067\u3059\u3002<\/span><span style=\"font-size: revert; color: initial;\">\u5909\u6570\u3092\u30ea\u30a2\u30af\u30c6\u30a3\u30d6\u306b\u3059\u308b\u305f\u3081\u306b\u306f\u6b21\u306b\u8aac\u660e\u3059\u308b<\/span><code>ref<\/code><span style=\"font-size: revert; color: initial;\">\u3068<\/span><code>reactive<\/code><span style=\"font-size: revert; color: initial;\">\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/span><\/p>\n<\/div>\n<p><!-- notionvc: 25eebec1-8bfa-40b9-aa39-112844ea877e --><\/p>\n<div class=\"questionBox\">\n<p><strong>\u30ea\u30a2\u30af\u30c6\u30a3\u30d6\u306a\u5024\u3068\u306f<\/strong><\/p>\n<p>\u5909\u6570\u306e\u5024\u3092\u5909\u66f4\u3059\u308b\u3068DOM\u3078\u306e\u53cd\u6620\u64cd\u4f5c\u3092JS\u3067\u8a18\u8ff0\u3057\u306a\u304f\u3068\u3082DOM\u3078\u81ea\u52d5\u53cd\u6620\u3055\u308c\u308b\u5c5e\u6027\u3092\u6301\u3064\u5909\u6570\u306e\u3053\u3068\u3092\u8a00\u3044\u307e\u3059\u3002<\/p>\n<\/div>\n\n\n<h3 id=\"outline__3_2\" class=\"wp-block-heading\">ref\/reactive<\/h3>\n\n\n<p>\u3067\u306f\u307e\u305a\u3001<code>ref<\/code>\u3092<code>vue<\/code>\u304b\u3089\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u3066\u4f7f\u7528\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<!-- notionvc: 43f5ff6b-d93a-40c2-b188-6152df4ea021 --><br \/><!-- notionvc: 946dc0a6-f714-41f1-b734-02888c76cd30 --><\/p>\n\n\n<pre class=\"wp-block-code\"><code>import { ref } from 'vue';\nconst count = ref(0);\nconst increment = () =&gt; count.value++;<\/code><\/pre>\n\n\n<p><code>ref<\/code>\u3067\u5b9a\u7fa9\u3057\u305f\u5909\u6570\u306e\u5024\u306f\u3001<code>value<\/code>\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u3088\u3063\u3066\u30a2\u30af\u30bb\u30b9\u304c\u53ef\u80fd\u3067\u3059\u3002<!-- notionvc: 80516c08-a927-4877-8d2d-a97bb00164fa -->\u305d\u306e\u305f\u3081\u3001<code>const increment = () =&gt; count++;<\/code>\u306e\u307e\u307e\u3067\u306f\u5909\u6570<code>count<\/code>\u306b\u76f4\u63a5\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u305b\u3093\u3002<!-- notionvc: c9d2be81-5ee7-488c-9b57-87927cc86b7e -->\u3057\u304b\u3057\u3001<code>&lt;template&gt;<\/code>\u5185\u3067\u306f<code>value<\/code>\u306e\u8a18\u8ff0\u306f\u4e0d\u8981\u306b\u306a\u308a\u307e\u3059\u3002<!-- notionvc: d4d5e75f-9d94-4f36-8b91-94abbb2b533d --><!-- notionvc: c9d2be81-5ee7-488c-9b57-87927cc86b7e --><\/p>\n\n\n<pre class=\"wp-block-code\"><code>&lt;template&gt;\n &lt;div&gt;{{ count }}&lt;\/div&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n<p>\u5909\u6570<code>count<\/code>\u306f\u30d7\u30ea\u30df\u30c6\u30a3\u30d6\u306a\u5024\u3067\u3057\u305f\u304c\u3001\u540c\u69d8\u306e\u65b9\u6cd5\u3067\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u30ea\u30a2\u30af\u30c6\u30a3\u30d6\u306b\u3059\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<!-- notionvc: e857c80c-74c7-4c96-8623-f90e142fd425 --><\/p>\n\n\n<pre class=\"wp-block-code\"><code>import { ref } from 'vue';\n\nconst obj = ref({ a: 0, b: 0 });\nconst increment = () =&gt; obj.value.a++;\nconst reset = () =&gt; obj.value = { a: 0, b: 0 };<\/code><\/pre>\n\n\n<p>\u3067\u3059\u304c\u3001<code>obj.value.a<\/code>\u3068\u3059\u308b\u306e\u306f\u5c11\u3057\u5197\u9577\u7684\u306b\u601d\u3048\u306a\u304f\u3082\u306a\u3044\u3067\u3059\u3002 <br \/>\u305d\u3053\u3067\u767b\u5834\u3059\u308b\u306e\u304c<code>reactive<\/code>\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n<pre class=\"wp-block-code\"><code>import { reactive } from \"vue\";\n\nconst obj = reactive({ a: 0, b: 0 });\nconst increment = () =&gt; obj.a++;\nconst reset = () =&gt; Object.assign(obj, { a: 0, b: 0 });<\/code><\/pre>\n\n\n<p><code>reactive<\/code>\u3067\u3042\u308c\u3070<code>value<\/code>\u3092\u4ed8\u3051\u305a\u306b\u30d7\u30ed\u30d1\u30c6\u30a3\u3078\u306e\u30a2\u30af\u30bb\u30b9\u304c\u53ef\u80fd\u306a\u306e\u3067\u3001\u3088\u308a\u76f4\u611f\u7684\u306b\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u4e8b\u304c\u3067\u304d\u307e\u3059\u3002\u3057\u304b\u3057<code>reactive<\/code>\u306e\u5834\u5408\u306f\u76f4\u63a5\u4ee3\u5165\u304c\u4e0d\u53ef\u80fd\u306a\u306e\u3067\u3001<code>Object.assign()<\/code>\u3092\u4f7f\u7528\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<!-- notionvc: c7aaad85-1a0e-4d71-9ab5-8f0d82435b4b --><\/p>\n<p>\u4e00\u822c\u7684\u306a\u4f7f\u3044\u5206\u3051\u3068\u3057\u3066\u3001\u300c\u30d7\u30ea\u30df\u30c6\u30a3\u30d6\u306a\u5024\u306f<code>ref<\/code>\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f<code>reactive<\/code>\u300d\u3068\u3044\u3046\u5370\u8c61\u304c\u3042\u308a\u307e\u3059\u304c\u3001<code>ref<\/code>\u306f<code>value<\/code>\u3092\u3064\u3051\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u4e00\u65b9\u3067\u3001\u4e00\u76ee\u898b\u3066\u30ea\u30a2\u30af\u30c6\u30a3\u30d6\u306a\u5024\u3060\u3068\u5224\u65ad\u3057\u3084\u3059\u3044\u306e\u3067\u3001\u597d\u307f\u306a\u3069\u304c\u306a\u3051\u308c\u3070\u57fa\u672c\u7684\u306b\u306f<code>ref<\/code>\u3092\u4f7f\u3046\u3067\u554f\u984c\u306a\u3044\u304b\u3068\u601d\u308f\u308c\u307e\u3059\u3002<!-- notionvc: 6349d818-d00f-49d6-b17e-6436cd3aa026 --><\/p>\n\n\n<h3 id=\"outline__3_3\" class=\"wp-block-heading\">computed\uff08\u7b97\u51fa\u30d7\u30ed\u30d1\u30c6\u30a3\uff09<\/h3>\n\n\n<p><span class=\"notion-enable-hover\" spellcheck=\"false\" data-token-index=\"0\"><code>computed<\/code><\/span>\u306f\u5024\u306e\u5909\u66f4\u304c\u3042\u308b\u305f\u3073\u306b\u81ea\u52d5\u3067\u51e6\u7406\u3092\u5b9f\u884c\u3057\u3001\u305d\u306e\u7d50\u679c\u30921\u3064\u3060\u3051\u8fd4\u3059\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002Options API\u3067\u306f<span class=\"notion-enable-hover\" spellcheck=\"false\" data-token-index=\"0\"><code>computed<\/code><\/span>\u30d7\u30ed\u30d1\u30c6\u30a3\u3068\u3057\u3066\u5b9a\u7fa9\u3057\u3066\u3044\u307e\u3057\u305f\u304c\u3001Composition API\u3067\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u4f7f\u7528\u3057\u307e\u3059\u3002<!-- notionvc: b7fbeb40-ef12-4eb9-b540-5a08828c7756 --><\/p>\n\n\n<pre class=\"wp-block-code\"><code>import { ref, computed } from 'vue';\n\nconst number = ref(1);\nconst doubleNumber = computed(() =&gt; number.value * 2);\n\nconst displaNumber = () =&gt; {\n  console.log(number.value, doubleNumber.value);\n}<\/code><\/pre>\n\n\n<p>\u4e0a\u8a18\u306e\u4f8b\u3067\u306f\u3001\u5909\u6570<code>number<\/code>\u3092\u4e8c\u500d\u306b\u3057\u305f<code>doubleNumber<\/code>\u3092<span class=\"notion-enable-hover\" spellcheck=\"false\" data-token-index=\"0\"><code>computed<\/code><\/span>\u3067\u5b9a\u7fa9\u3057\u3066\u3044\u307e\u3059\u3002 <span class=\"notion-enable-hover\" spellcheck=\"false\" data-token-index=\"0\"><code>computed<\/code><\/span>\u306e\u5024\u306f<code>ref<\/code>\u3068\u540c\u69d8<code>value<\/code>\u30d7\u30ed\u30d1\u30c6\u30a3\u7d4c\u7531\u3067\u30a2\u30af\u30bb\u30b9\u3057\u307e\u3059\u3002<!-- notionvc: 4106b6e5-cd00-460e-97af-0acf9a1b1fea --><\/p>\n<p>\u307e\u305f\u3001<span class=\"notion-enable-hover\" spellcheck=\"false\" data-token-index=\"0\"><code>computed<\/code><\/span>\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u3067Getter\u3068\u3057\u3066\u52d5\u4f5c\u3057\u307e\u3059\u304c\u3001Setter\u3082\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u3066\u304a\u308a\u3001\u66f8\u304d\u8fbc\u307f\u304c\u53ef\u80fd\u306a<span class=\"notion-enable-hover\" spellcheck=\"false\" data-token-index=\"0\"><code>computed<\/code><\/span>\u306e\u3053\u3068\u3092<span class=\"notion-enable-hover\" spellcheck=\"false\" data-token-index=\"0\"><code>Writable Computed<\/code><\/span>\u3068\u3044\u3044\u307e\u3059\u3002<\/p>\n\n\n<pre class=\"wp-block-code\"><code>&lt;template&gt;\n  &lt;input type=\"number\" v-model=\"doubleNumber\" \/&gt;\n&lt;\/template&gt;\n\n&lt;script setup&gt;\nimport  { ref, computed } from 'vue'\nconst number = ref(1)\nconst doubleNumber= computed({\n get: () =&gt; number.value * 2,\n set: (val) =&gt; {\n    number.value = val\n  }\n})\n&lt;\/script&gt;<\/code><\/pre>\n\n\n<p><span class=\"notion-enable-hover\" spellcheck=\"false\" data-token-index=\"0\"><code>Writable Computed<\/code><\/span>\u306f<span class=\"notion-enable-hover\" spellcheck=\"false\" data-token-index=\"0\"><code>v-model<!-- notionvc: 068c0aff-acaf-4445-bc73-0e54b0c4b5b5 --><\/code><\/span>\u3092\u4f7f\u7528\u3059\u308b\u969b\u306a\u3069\u306b\u3068\u3066\u3082\u4fbf\u5229\u3067\u3059\u3002\u4e0a\u8a18\u306e\u4f8b\u3067\u306f\u3001<span class=\"notion-enable-hover\" spellcheck=\"false\" data-token-index=\"0\"><code>input<\/code><\/span>\u306b\u5165\u529b\u3055\u308c\u305f\u6570\u5024\u3092\u81ea\u52d5\u7684\u306b2\u500d\u306b\u3057\u3066\u8fd4\u3059\u51e6\u7406\u3092\u884c\u306a\u3063\u3066\u3044\u307e\u3059\u3002<!-- notionvc: c94d7a2a-04ef-4614-aaa1-f4709e5da66c --><\/p>\n\n\n<h3 id=\"outline__3_4\" class=\"wp-block-heading\">props<\/h3>\n\n\n<p><span class=\"notion-enable-hover\" spellcheck=\"false\" data-token-index=\"0\"><code>props<\/code><\/span>\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001<span class=\"notion-enable-hover\" data-token-index=\"2\">\u89aa\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304b\u3089\u5b50\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3078\u30c7\u30fc\u30bf\u3092\u6e21\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059<\/span>\u3002\u89aa\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d7\u3051\u53d6\u308b\u305f\u3081\u306b\u306f\u3001\u5b50\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5074\u3067<span class=\"notion-enable-hover\" spellcheck=\"false\" data-token-index=\"0\"><code>defineProps<\/code><\/span>\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<!-- notionvc: 2d8f95f6-61a8-4d74-83b1-1a6b1a1030ec --><\/p>\n\n\n<pre class=\"wp-block-code\"><code>const props = defineProps&lt;{\n  message: string\n}&gt;();<\/code><\/pre>\n\n\n<p>\u4e0a\u8a18\u306e\u4f8b\u3067\u306f\u3001<code>message<\/code>\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u30c7\u30fc\u30bf\u578b\u3092<code>string<\/code>\u3068\u3057\u3066\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002\u53d7\u3051\u53d6\u3063\u305f\u5024\u306f<code>props.message<\/code>\u306e\u3088\u3046\u306b\u30a2\u30af\u30bb\u30b9\u3057\u307e\u3059\u304c\u3001<code>&lt;template&gt;<\/code>\u5185\u3067\u306f<span class=\"notion-enable-hover\" spellcheck=\"false\" data-token-index=\"0\"><code>props<\/code><\/span>\u306f\u4e0d\u8981\u3067\u3059\u3002<\/p>\n\n\n<pre class=\"wp-block-code\"><code>&lt;template&gt;\n &lt;div&gt;{{ message }}&lt;\/div&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n<p>\u7d9a\u3044\u3066\u3001\u89aa\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304b\u3089<span class=\"notion-enable-hover\" spellcheck=\"false\" data-token-index=\"0\"><code>props<\/code><\/span>\u3092\u6e21\u3059\u306b\u306f\u3001\u5b50\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u547c\u3073\u51fa\u3059\u969b\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u307e\u3059\u3002<!-- notionvc: c351a535-b0ca-41f0-be02-0674a447600c --><\/p>\n\n\n<pre class=\"wp-block-code\"><code>&lt;template&gt;\n  &lt;div&gt;\n    &lt;ChildComponent message=\"Hello world!\" \/&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;\n\n&lt;script setup&gt;\nimport ChildComponent from '.\/ChildComponent.vue';\n&lt;\/script&gt;<\/code><\/pre>\n\n\n<p>\u3053\u308c\u306b\u3088\u308a\u3001<code>message<\/code>\u30d7\u30ed\u30d1\u30c6\u30a3\u306b<code>\"Hello world!\"<\/code>\u3068\u3044\u3046\u5024\u304c\u6e21\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n<h3 id=\"outline__3_5\" class=\"wp-block-heading\">emit<\/h3>\n\n\n<p><code>emit<\/code>\u3067\u306f\u3001\u30a4\u30d9\u30f3\u30c8\u3092\u5229\u7528\u3057\u3066\u5b50\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304b\u3089\u89aa\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3078\u901a\u77e5\u3092\u884c\u3044\u3001\u30a4\u30d9\u30f3\u30c8\u3068\u4e00\u7dd2\u306b\u89aa\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u30c7\u30fc\u30bf\u3092\u6e21\u3059\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<!-- notionvc: 1bf535e1-dc84-466a-a0af-f7143fb01339 -->\u89aa\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3078\u30a4\u30d9\u30f3\u30c8\u3092\u901a\u77e5\u3059\u308b\u306b\u306f\u3001\u5b50\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5074\u3067<code>defineEmits<\/code>\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n\n\n<pre class=\"wp-block-code\"><code>&lt;template&gt;\n  &lt;div&gt;\n    &lt;button @click=\"sendMessage\"&gt;Send Message!&lt;\/button&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;\n\n&lt;script setup&gt;\nimport { ref } from 'vue';\n\nconst emit = defineEmits&lt;{\n  (e: 'sendMessage', message: string): void\n}&gt;();\n\nconst message = ref('Hello world!');\nconst sendMessage = () =&gt; {\n  emit('sendMessage', message);\n};\n&lt;\/script&gt;<\/code><\/pre>\n\n\n<p><code>emit<\/code>\u306f2\u3064\u4ee5\u4e0a\u306e\u5f15\u6570\u3092\u53d6\u308b\u305f\u3081\u3001<code>emit<\/code>\u306e\u7b2c\u4e00\u5f15\u6570\u306b\u306f\u30c8\u30ea\u30ac\u30fc\u3057\u305f\u3044\u30a4\u30d9\u30f3\u30c8\u306e\u540d\u524d\u3092\u3001\u7b2c\u4e8c\u5f15\u6570\u4ee5\u964d\u306b\u306f\u89aa\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u6e21\u3057\u305f\u3044\u30c7\u30fc\u30bf\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<!-- notionvc: 83bb1882-cf6e-4adc-8b20-2e3d9fb01aa4 --><\/p>\n<p>\u307e\u305f\u3001\u89aa\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3067\u30c7\u30fc\u30bf\u3092\u53d7\u3051\u53d6\u308b\u969b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n<pre class=\"wp-block-code\"><code>&lt;template&gt;\n  &lt;ChildComponent @sendMessage=\"sendMessage\" \/&gt;\n&lt;\/template&gt;\n\n&lt;script setup&gt;\nimport ChildComponent from '.\/ChildComponent.vue';\n\nconst sendMessage = (message: string) =&gt; {\n  console.log(message);\n}\n&lt;\/script&gt;<\/code><\/pre>\n\n\n<p>\u3053\u308c\u306b\u3088\u308a\u3001\u30dc\u30bf\u30f3\u30af\u30ea\u30c3\u30af\u3067<code>sendMessage<\/code>\u3068\u3044\u3046\u30a4\u30d9\u30f3\u30c8\u306e\u901a\u77e5\u3068\u5171\u306b<code>message<\/code>\u306e\u5024\u3092\u89aa\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u9001\u4fe1\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n<h3 id=\"outline__3_6\" class=\"wp-block-heading\">\u30e9\u30a4\u30d5\u30b5\u30a4\u30af\u30eb\u30d5\u30c3\u30af<\/h3>\n\n\n<p>\u30e9\u30a4\u30d5\u30b5\u30a4\u30af\u30eb\u30d5\u30c3\u30af\u3068\u306f\u3001Vue\u3067\u4f5c\u6210\u3057\u305f\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304c\u751f\u6210\u3055\u308c\u3066\u3001\u6d88\u3048\u308b\u307e\u3067\u306e\u72b6\u614b\u9077\u79fb\u306e\u3053\u3068\u3092\u8a00\u3044\u3001Options API\u3068Composition API\u3067\u95a2\u6570\u540d\u304c\u82e5\u5e72\u7570\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Options API (vue2)<\/strong><\/td><td><strong>Composition API (vue3)<\/strong><\/td><\/tr><tr><td>beforeCreate<\/td><td>&#8211;<\/td><\/tr><tr><td>created<\/td><td>&#8211;<\/td><\/tr><tr><td>beforeMount<\/td><td>onBeforeMount()<\/td><\/tr><tr><td>mounted<\/td><td>onMounted()<\/td><\/tr><tr><td>beforeUpdate<\/td><td>onBeforeUpdate()<\/td><\/tr><tr><td>updated<\/td><td>onUpdated()<\/td><\/tr><tr><td>beforeDestroy<\/td><td>onBeforeUnount()<\/td><\/tr><tr><td>destroyed<\/td><td>onUnmounted()<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n<p>Composition API\u3067\u306f\u3001<code>&lt;script setup&gt;<\/code>\u5185\u306b\u5b9a\u7fa9\u3057\u305f\u3059\u3079\u3066\u306e\u51e6\u7406\u304c<code>beforeCreate<\/code>\u3068<code><span class=\"notion-enable-hover\" spellcheck=\"false\" data-token-index=\"5\">created<\/span><\/code>\u306b\u8a72\u5f53\u3057\u307e\u3059\u3002 \u305d\u306e\u305f\u3081\u3001\u3053\u306e2\u3064\u306f\u95a2\u6570\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002<!-- notionvc: 2575033a-7e2b-4272-9d58-0fef9398e7fa --><\/p>\n<p>\u30e9\u30a4\u30d5\u30b5\u30a4\u30af\u30eb\u30d5\u30c3\u30af\u3092\u4f7f\u7528\u3059\u308b\u969b\u306f<code>vue<\/code>\u304b\u3089<code><span class=\"notion-enable-hover\" spellcheck=\"false\" data-token-index=\"1\">import<\/span><\/code>\u3057\u3066\u4f7f\u3044\u307e\u3059\u3002<\/p>\n\n\n<h2 id=\"outline__4\" class=\"wp-block-heading\">\u6700\u5f8c\u306b<\/h2>\n\n\n<p>Composition API\u306e\u57fa\u672c\u306b\u3064\u3044\u3066\u7d39\u4ecb\u3057\u3066\u3044\u304d\u307e\u3057\u305f\u304c\u3001Composition API\u72ec\u81ea\u306e\u6a5f\u80fd\u306f\u307e\u3060\u3044\u304f\u3064\u304b\u3042\u308a\u307e\u3059\u3002\u5404\u30e9\u30a4\u30d5\u30b5\u30a4\u30af\u30eb\u30d5\u30c3\u30af\u306e\u8a73\u7d30\u306a\u8aac\u660e\u306a\u3069\u3001\u7701\u7565\u3057\u3066\u3044\u308b\u90e8\u5206\u3082\u7d50\u69cb\u3042\u308b\u306e\u3067\u3001Vue3\u3082\u3068\u3044Composition API\u306b\u8208\u5473\u306e\u3042\u308b\u65b9\u3084\u696d\u52d9\u3067\u4f7f\u7528\u3057\u3066\u3044\u308b\u65b9\u306f\u3001\u305c\u3072\u8272\u3005\u8abf\u3079\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n<blockquote class=\"wp-embedded-content\" data-secret=\"NMc8kvuJic\"><a href=\"https:\/\/techmania.jp\/blog\/javascript0005\/\">Vue.js\u3068\u306f\u3010\u5165\u9580\u3011\u30e1\u30ea\u30c3\u30c8\u30fb\u7279\u5fb4\u6bd4\u8f03\u3067\u308f\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Vue.js\u3068\u306f\u3010\u5165\u9580\u3011\u30e1\u30ea\u30c3\u30c8\u30fb\u7279\u5fb4\u6bd4\u8f03\u3067\u308f\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac&#8221; &#8212; TechMania\" src=\"https:\/\/techmania.jp\/blog\/javascript0005\/embed\/#?secret=sf3ErfTc3t#?secret=NMc8kvuJic\" data-secret=\"NMc8kvuJic\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n\n\n\n<blockquote class=\"wp-embedded-content\" data-secret=\"LfRYrmPBBK\"><a href=\"https:\/\/techmania.jp\/blog\/vue-js3\/\">Vue.js3\u3068\u306f\uff1f\u7279\u5fb4\u30fb\u74b0\u5883\u69cb\u7bc9\u306e\u3084\u308a\u65b9\u3092\u89e3\u8aac<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Vue.js3\u3068\u306f\uff1f\u7279\u5fb4\u30fb\u74b0\u5883\u69cb\u7bc9\u306e\u3084\u308a\u65b9\u3092\u89e3\u8aac&#8221; &#8212; TechMania\" src=\"https:\/\/techmania.jp\/blog\/vue-js3\/embed\/#?secret=bqzRXmUi04#?secret=LfRYrmPBBK\" data-secret=\"LfRYrmPBBK\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n","protected":false},"excerpt":{"rendered":"Composition API\u3068\u306f\uff1f Composition API\u3068\u306f\u3001Vue3\u304b\u3089\u5c0e\u5165\u3055\u308c\u305f\u65b0\u6a5f\u80fd\u3067\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u5b9f\u88c5\u3059\u308bAPI\u3092\u6307\u3057\u307e\u3059\u3002\u300c\u30ea\u30a2\u30af\u30c6\u30a3\u30d6\u306a\u5024\u3084\u305d\u308c\u306b\u95a2\u9023\u3057\u305f\u95a2\u6570\u3092\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304b\u3089\u5207\u308a\u96e2\u3057\u3066\u6271\u3048\u308b\u300d\u3068\u3044\u3046\u7279\u5fb4\u3092\u6301\u3064\u3053\u3068\u304b\u3089\u3001\u30b3\u30fc\u30c9\u306e\u518d\u5229\u7528\u6027\u3084\u4fdd\u5b88\u6027\u306e\u5411\u4e0a\u304c\u671f\u5f85\u3055\u308c\u3066\u3044\u307e\u3059\u3002Vue2\u306e\u30b5\u30dd\u30fc\u30c8\u304c2023\u5e7412\u670831\u65e5\u3092\u3082\u3063\u3066\u7d42\u4e86\u3057\u305f\u305f\u3081\u3001Vue2\u304b\u3089Vue3\u3078\u306e\u79fb\u884c\u3092\u691c\u8a0e\u3057 [&hellip;]","protected":false},"author":8,"featured_media":6647,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6639","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/techmania.jp\/blog\/wp-json\/wp\/v2\/posts\/6639","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techmania.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techmania.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techmania.jp\/blog\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/techmania.jp\/blog\/wp-json\/wp\/v2\/comments?post=6639"}],"version-history":[{"count":7,"href":"https:\/\/techmania.jp\/blog\/wp-json\/wp\/v2\/posts\/6639\/revisions"}],"predecessor-version":[{"id":6653,"href":"https:\/\/techmania.jp\/blog\/wp-json\/wp\/v2\/posts\/6639\/revisions\/6653"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techmania.jp\/blog\/wp-json\/wp\/v2\/media\/6647"}],"wp:attachment":[{"href":"https:\/\/techmania.jp\/blog\/wp-json\/wp\/v2\/media?parent=6639"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techmania.jp\/blog\/wp-json\/wp\/v2\/categories?post=6639"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techmania.jp\/blog\/wp-json\/wp\/v2\/tags?post=6639"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}