{"id":2499,"date":"2018-11-21T03:01:04","date_gmt":"2018-11-20T18:01:04","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=2499"},"modified":"2018-11-21T03:01:04","modified_gmt":"2018-11-20T18:01:04","slug":"%e5%88%9d%e5%bf%83%e8%80%85%e5%90%91%e3%81%8d%ef%bc%81vuejs-%e3%81%a7%ef%bc%93%e6%8a%9e%e3%82%af%e3%82%a4%e3%82%ba%e3%82%b2%e3%83%bc%e3%83%a0%e3%82%92%e3%81%a4%e3%81%8f%e3%81%a3%e3%81%a6%e3%81%bf","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=2499","title":{"rendered":"\u521d\u5fc3\u8005\u5411\u304d\uff01VueJS \u3067\uff13\u629e\u30af\u30a4\u30ba\u30b2\u30fc\u30e0\u3092\u3064\u304f\u3063\u3066\u307f\u3088\u3046"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3053\u306e\u30d6\u30ed\u30b0\u3067\u306f\u3067\u304d\u308b\u3060\u3051\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u697d\u3057\u3055\u3092\u591a\u304f\u306e\u4eba\u306b\u77e5\u3063\u3066\u3082\u3089\u3044\u305f\u3044\u3068\u3044\u3046\u6c17\u6301\u3061\u3067\u516c\u958b\u3057\u3066\u3044\u308b\u8a18\u4e8b\u3082\u591a\u304f\u3042\u308b\u306e\u3067\u3059\u304c\u3001\u3069\u3046\u3057\u3066\u3082\u6271\u3063\u3066\u3044\u308b\u306e\u304c\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3068\u3044\u3046\u3053\u3068\u3067\u5185\u5bb9\u304c\u8907\u96d1\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u308a\u3001\u30c6\u30fc\u30de\u304c\u696d\u52d9\u7684\u306a\u5185\u5bb9\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u3069\u3046\u3057\u305f\u3082\u3093\u304b\u306a\u3001\u306a\u3093\u3066\u8003\u3048\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u79c1\u306e\u7d4c\u9a13\u4e0a\uff08\u30d4\u30a2\u30ce\u3084\u82f1\u8a9e\uff09\u3067\u305d\u3046\u3060\u3063\u305f\u3093\u3067\u3059\u304c\u3001\u3084\u306f\u308a\u5b66\u3076\u306b\u306f\u3067\u304d\u308b\u3060\u3051\u597d\u304d\u306a\u3082\u306e\u3068\u304f\u3063\u3064\u3051\u308b\u3068\u9577\u7d9a\u304d\u307e\u3059\u3057\u3001\u899a\u3048\u3082\u65e9\u304b\u3063\u305f\u306e\u3067\u3001\u4eca\u56de\u306f\u300c\u4ed5\u4e8b\u306b\u76f4\u7d50\u3057\u306a\u3044\u3051\u3069\u3001\u5b66\u3076\u306b\u306f\u3044\u3044\u3060\u308d\u3046\u300d\u3068\u3044\u3046\u5185\u5bb9\u3067\u8a18\u4e8b\u3092\u66f8\u3044\u3066\u307f\u308b\u3053\u3068\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u958b\u767a\u3059\u308b\u5185\u5bb9\u306f\u30ba\u30d0\u30ea<strong>\u300c\uff13\u629e\u30af\u30a4\u30ba\u300d<\/strong>\u3067\u3059\u3002<\/p>\n<p>\uff13\u629e\u30af\u30a4\u30ba\u306f\u30c6\u30ec\u30d3\u756a\u7d44\u306a\u3093\u304b\u3067\u3082\u3088\u304f\u898b\u308b\u30af\u30a4\u30ba\u5f62\u5f0f\u306a\u306e\u3067\u3001\u984c\u6750\u3068\u3057\u3066\u306f\u304d\u3063\u3068\u3044\u3044\u306e\u3067\u306f\u306a\u3044\u304b\u3068\u8003\u3048\u307e\u3057\u305f\u3002<\/p>\n<p>\u3082\u3061\u308d\u3093\u3001\u521d\u5fc3\u8005\u306b\u3082\u3067\u304d\u308b\u3060\u3051\u5206\u304b\u308a\u3084\u3059\u304f\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u305c\u3072\u697d\u3057\u307f\u306a\u304c\u3089\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306b\u89e6\u308c\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u306d\u3002\uff08\u6700\u5f8c\u306b\u6559\u6750\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\uff12\u3064\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3067\u304d\u307e\u3059\uff01\uff09<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2158 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/29.png\" alt=\"\" width=\"170\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/29.png 170w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/29-159x300.png 159w\" sizes=\"auto, (max-width: 170px) 100vw, 170px\" \/><\/p>\n<p>\u203b \u74b0\u5883\uff1a Google Chrome 70, Vue 2<\/p>\n<h1>\u3084\u308a\u305f\u3044\u3053\u3068<\/h1>\n<ul>\n<li>\uff11\u554f\u305a\u3064\u30af\u30a4\u30ba\u3092\u8868\u793a<\/li>\n<li>\u89e3\u7b54\u306f\uff13\u629e<\/li>\n<li>\u6700\u5f8c\u306b\u7d50\u679c\u3092\u8868\u793a\u3059\u308b<\/li>\n<\/ul>\n<h1>\u30ec\u30a4\u30a2\u30a6\u30c8\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3067\u306f\u307e\u305a\u306f\uff13\u629e\u30af\u30a4\u30ba\u306e\u30ec\u30a4\u30a2\u30a6\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<br \/>\n\u4eca\u56de\u306fCSS\u306b<code>bootstrap<\/code>\u3001JavaScript\u306b<code>Vue.js<\/code>\u3092\u4f7f\u3044\u307e\u3059\u304c\u3001\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u4e0a\u304b\u3089\u547c\u3073\u51fa\u3059\u306e\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306f\u5fc5\u8981\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<pre>&lt;html&gt;\r\n&lt;head&gt;\r\n    <strong>&lt;link href=\"https:\/\/stackpath.bootstrapcdn.com\/bootstrap\/4.1.3\/css\/bootstrap.min.css\" rel=\"stylesheet\"&gt;<\/strong>\r\n    &lt;style&gt;\r\n\r\n        body {\r\n            padding: 50px;\r\n        }\r\n\r\n    &lt;\/style&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n    &lt;div id=\"app\" class=\"row\"&gt;\r\n        &lt;div class=\"offset-3 col-6\"&gt;\r\n            &lt;div class=\"card\"&gt;\r\n                &lt;div class=\"card-body\"&gt;\r\n                    &lt;p class=\"badge badge-dark\"&gt;\u7b2c 1 \u554f&lt;\/p&gt;\r\n                    &lt;br&gt;\r\n                    &lt;h4 class=\"card-title\"&gt;\u56f2\u7881\u306e\u77f3\u306e\u5927\u304d\u3055\u306f\u3069\u3063\u3061\u304c\u5927\u304d\u3044\uff1f&lt;\/h4&gt;\r\n                    &lt;hr&gt;\r\n                    &lt;button type=\"button\" class=\"btn btn-primary btn-lg btn-block text-left\"&gt;1. \u767d\u3044\u77f3&lt;\/button&gt;\r\n                    &lt;button type=\"button\" class=\"btn btn-primary btn-lg btn-block text-left\"&gt;2. \u9ed2\u3044\u77f3&lt;\/button&gt;\r\n                    &lt;button type=\"button\" class=\"btn btn-primary btn-lg btn-block text-left\"&gt;3. \u3069\u3061\u3089\u3082\u540c\u3058&lt;\/button&gt;\r\n                &lt;\/div&gt;\r\n            &lt;\/div&gt;\r\n        &lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n    <strong>&lt;script src=\"https:\/\/cdn.jsdelivr.net\/npm\/vue@2.5.17\/dist\/vue.min.js\"&gt;&lt;\/script&gt;<\/strong>\r\n    &lt;script&gt;\r\n\r\n        new Vue({\r\n            el: '#app'\r\n        })\r\n\r\n    &lt;\/script&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\u3053\u308c\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2506\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/quiz_3.png\" alt=\"\" width=\"657\" height=\"344\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/quiz_3.png 657w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/quiz_3-300x157.png 300w\" sizes=\"auto, (max-width: 657px) 100vw, 657px\" \/><\/p>\n<p>\u3067\u306f\u3053\u306e\u30ec\u30a4\u30a2\u30a6\u30c8\u3092\u4f7f\u3063\u3066JavaScript\uff08Vue.js\uff09\u90e8\u5206\u3092\u4f5c\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h1>JavaScript\u90e8\u5206\u3092\u3064\u304f\u308b<\/h1>\n<h2>\u30af\u30a4\u30ba\u3092\u8868\u793a\u3059\u308b\u90e8\u5206\u3092\u3064\u304f\u308b<\/h2>\n<p>\u3067\u306f\u3001\u30af\u30a4\u30ba\u3092\u8868\u793a\u3059\u308b\u90e8\u5206\u3067\u3059\u3002<br \/>\n\u307e\u305a\u306f\u3001<code>questions<\/code>\u3068\u3044\u3046\u540d\u524d\u306e\u5909\u6570\u3092<code>data<\/code>\u306b\u767b\u9332\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>new Vue({\r\n    el: '#app',\r\n    data: {\r\n        <strong>questions: [<\/strong>\r\n<strong>            {<\/strong>\r\n<strong>                question: '\u56f2\u7881\u306e\u77f3\u306e\u5927\u304d\u3055\u306f\u3069\u3063\u3061\u304c\u5927\u304d\u3044\uff1f',<\/strong>\r\n<strong>                answers: [<\/strong>\r\n<strong>                    '\u767d\u3044\u77f3',<\/strong>\r\n<strong>                    '\u9ed2\u3044\u77f3',<\/strong>\r\n<strong>                    '\u3069\u3061\u3089\u3082\u540c\u3058',<\/strong>\r\n<strong>                ],<\/strong>\r\n<strong>                answer: 1<\/strong>\r\n<strong>            },<\/strong>\r\n<strong>            {<\/strong>\r\n<strong>                question: '\u30b3\u30f3\u30d3\u30cb\u30c1\u30a7\u30fc\u30f3\u306e\u30bb\u30d6\u30f3\u30a4\u30ec\u30d6\u30f3\u3002\u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u8868\u8a18\u3067\uff11\u6587\u5b57\u3060\u3051\u5c0f\u6587\u5b57\u306a\u306e\u306f\uff1f',<\/strong>\r\n<strong>                answers: [<\/strong>\r\n<strong>                    'N',<\/strong>\r\n<strong>                    'L',<\/strong>\r\n<strong>                    'V',<\/strong>\r\n<strong>                ],<\/strong>\r\n<strong>                answer: 0<\/strong>\r\n<strong>            },<\/strong>\r\n<strong>            {<\/strong>\r\n<strong>                question: '\u30ab\u30e9\u30aa\u30b1\u306f\u300c\u7a7a\u25cb\u25cb\u300d\u7565\u3067\u3059\u3002\u7a7a\u6b04\u306b\u5165\u308b\u8a00\u8449\u306f\u4f55\uff1f',<\/strong>\r\n<strong>                answers: [<\/strong>\r\n<strong>                    'OK',<\/strong>\r\n<strong>                    '\u30aa\u30fc\u30b1\u30b9\u30c8\u30e9',<\/strong>\r\n<strong>                    '\u304a\u3051\u3089',<\/strong>\r\n<strong>                ],<\/strong>\r\n<strong>                answer: 1<\/strong>\r\n<strong>            }<\/strong>\r\n<strong>        ]<\/strong>\r\n    }\r\n})<\/pre>\n<p><code>questions<\/code>\u306f\u914d\u5217\u3067\u3001\u305d\u306e\u4e2d\u8eab\u306f\u30af\u30a4\u30ba\u306e\u6587\u7ae0\u3084\u9078\u629e\u80a2\u3001\u7b54\u3048\u304c\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u683c\u7d0d\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u73fe\u5728\u306e\u30af\u30a4\u30ba\u756a\u53f7\u3092\u4fdd\u6301\u3059\u308b<code>questionIndex<\/code>\u3082\u8ffd\u52a0\u3057\u307e\u3059\u3002<br \/>\n\u521d\u671f\u5024\u306f\u3082\u3061\u308d\u3093<code>0<\/code>\u3067\u3059\u3002<\/p>\n<pre>data: {\r\n    <strong>questionIndex: 0,<\/strong>\r\n    \r\n    \/\/ \u7701\u7565\r\n\r\n}<\/pre>\n<p>\u6b21\u306b\u73fe\u5728\u306e\u30af\u30a4\u30ba\u5185\u5bb9\u3092\u81ea\u52d5\u7684\u306b\u53d6\u5f97\u3067\u304d\u308b\u7591\u4f3c\u5909\u6570<code>currentQuestion<\/code>\u3092<code>computed<\/code>\u306b\u3064\u304f\u308a\u307e\u3059\u3002<\/p>\n<pre>computed: {\r\n    <strong>currentQuestion: function() {<\/strong>\r\n\r\n<strong>        return this.questions[this.questionIndex];<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n}<\/pre>\n<p>\u3053\u308c\u3067\u3001\u30ec\u30a4\u30a2\u30a6\u30c8\u306e\u4e2d\u3067<code>currentQuestion<\/code>\u3068\u3059\u308c\u3070\u73fe\u5728\u306e\u30af\u30a4\u30ba\u5185\u5bb9\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001\u3053\u308c\u3089\u306e\u5909\u6570\u3092\u3064\u304b\u3063\u3066\u5b9f\u969b\u306b\u8868\u793a\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u307e\u305a\u306f\u7b2c \u25cb \u554f\u306e\u90e8\u5206\u3067\u3059\u3002<\/p>\n<pre>&lt;p class=\"badge badge-dark\"&gt;\u7b2c <strong>{{ (questionIndex+1) }}<\/strong> \u554f&lt;\/p&gt;<\/pre>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u4e0a\u3067\u306f\u914d\u5217\u306e\u756a\u53f7\u306f0\u304b\u3089\u59cb\u307e\u308b\u306e\u3067<code>questionIndex<\/code>\u306e\u521d\u671f\u5024\u306f<code>0<\/code>\u306b\u3057\u307e\u3057\u305f\u3002<br \/>\n\u3057\u304b\u3057\u3001\u3053\u306e\u307e\u307e\u3060\u3068 <strong>&#8220;\u7b2c 0 \u554f&#8221;<\/strong> \u306b\u306a\u3063\u3066\u3057\u307e\u3046\u306e\u3067\u3001<code>1<\/code>\u3092\u8db3\u3057\u305f\u7d50\u679c\u3092\u8868\u793a\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u8cea\u554f\u304c\u8868\u793a\u3055\u308c\u308b\u90e8\u5206\u3067\u3059\u3002<br \/>\n\u5148\u307b\u3069\u3064\u304f\u3063\u305f\u7591\u4f3c\u5909\u6570<code>currentQuestion<\/code>\u304b\u3089\u8cea\u554f\u90e8\u5206\u3092\u53d6\u5f97\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre>&lt;h4 class=\"card-title\"&gt;<strong>{{ currentQuestion.question }}<\/strong>&lt;\/h4&gt;<\/pre>\n<p>\u7d9a\u3044\u3066\uff13\u629e\u306e\u90e8\u5206\u3067\u3059\u3002<br \/>\n\u3053\u3053\u306f\u8868\u793a\u3059\u3079\u304d\u30c7\u30fc\u30bf\u304c\uff13\u3064\u3042\u308b\u306e\u3067\u3001\u30eb\u30fc\u30d7\u3092\u4f7f\u3063\u3066\u4e00\u6c17\u306b\u8868\u793a\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>&lt;button\r\n    type=\"button\"\r\n    class=\"btn btn-primary btn-lg btn-block text-left\"\r\n    <strong>v-for=\"(answer,index) in currentQuestion.answers\"<\/strong>&gt;{{ (index+1) }}. {{ answer }}&lt;\/button&gt;<\/pre>\n<p>\u307e\u305a\u3001<code>v-for<\/code>\u306e\u4e2d\u8eab\u3067\u3059\u304c\u3001<\/p>\n<pre><strong>(answer,index) in currentQuestion.answers<\/strong><\/pre>\n<p>\u3068\u3059\u308b\u3053\u3068\u3067\u3001<code>currentQuestion.anwers<\/code>\u304b\u3089\uff11\u3064\u305a\u3064\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u305d\u3057\u3066\u3001<code>answer<\/code>\u306b\u306f\u89e3\u7b54\u306e\u9078\u629e\u80a2\uff08\u4f8b\u3048\u3070\u300c\u767d\u3044\u77f3\u300d\u306a\u3069\uff09\u304c\u683c\u7d0d\u3055\u308c\u3001<code>index<\/code>\u306f<code>0<\/code>\u304b\u3089\u59cb\u307e\u308b\u756a\u53f7\u3067\u3059\u3002<\/p>\n<p>\u5b9f\u884c\u3059\u308b\u3068HTML\u306f\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><strong>&lt;button type=\"button\" class=\"btn btn-primary btn-lg btn-block text-left\"&gt;1. \u767d\u3044\u77f3&lt;\/button&gt;<\/strong>\r\n<strong>&lt;button type=\"button\" class=\"btn btn-primary btn-lg btn-block text-left\"&gt;2. \u9ed2\u3044\u77f3&lt;\/button&gt;<\/strong>\r\n<strong>&lt;button type=\"button\" class=\"btn btn-primary btn-lg btn-block text-left\"&gt;3. \u3069\u3061\u3089\u3082\u540c\u3058&lt;\/button&gt;<\/strong><\/pre>\n<h2>\u89e3\u7b54\u3057\u305f\u3068\u304d\u306e\u51e6\u7406\u3092\u3064\u304f\u308b<\/h2>\n<p>\u30af\u30a4\u30ba\u306e\u8868\u793a\u306f\u5b8c\u4e86\u3057\u305f\u306e\u3067\u3001\u7d9a\u3044\u3066\u89e3\u7b54\u3057\u305f\u6642\uff08\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3057\u305f\u6642\uff09\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u3064\u304f\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u307e\u305a\u5168\u3066\u306e\u89e3\u7b54\u3092\u4fdd\u6301\u3057\u3066\u304a\u304f\u5909\u6570\uff08\u914d\u5217\uff09\u3001<code>answers<\/code>\u3092\u767b\u9332\u3057\u307e\u3059\u3002<\/p>\n<pre>data: {\r\n    <strong>answers: [],\r\n\r\n    \/\/ \u7701\u7565\r\n<\/strong>\r\n}<\/pre>\n<p>\u5148\u307b\u3069\u306e\u30dc\u30bf\u30f3\u90e8\u5206\u306b\u30af\u30ea\u30c3\u30af\u30a4\u30d9\u30f3\u30c8\u3001<code>@click=\"answer(index)\"<\/code>\u3092\u4ed8\u3051\u307e\u3059\u3002<\/p>\n<pre>&lt;button\r\n    type=\"button\"\r\n    class=\"btn btn-primary btn-lg btn-block text-left\"\r\n    v-for=\"(answer,index) in currentQuestion.answers\"\r\n    <strong>@click=\"addAnswer(index)\"<\/strong>&gt;{{ (index+1) }}. {{ answer }}&lt;\/button&gt;<\/pre>\n<p>\u305d\u3057\u3066\u3001<code>addAnswer()<\/code>\u306e\u672c\u4f53\u3067\u3059\u3002<\/p>\n<pre>addAnswer: function(index) {\r\n\r\n    this.answers.push(index);\r\n\r\n    <strong>if(this.questions.length == this.answers.length) {<\/strong>\r\n\r\n        \/\/ \u30af\u30a4\u30ba\u304c\u5b8c\u4e86\u3057\u305f\u3068\u304d\r\n\r\n   <strong> } else {<\/strong>\r\n\r\n        <strong>this.questionIndex++;<\/strong>\r\n\r\n    <strong>}<\/strong>\r\n\r\n}<\/pre>\n<p>\u307e\u305a\u7b54\u3048\u3066\u3044\u304f\u5ea6\u306b<code>answers<\/code>\u306e\u4e2d\u8eab\u304c\u3072\u3068\u3064\u305a\u3064\u5897\u3048\u3066\u3044\u304f\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u8cea\u554f\u306e\u6570\u3068\u89e3\u7b54\u306e\u6570\u3092\u6bd4\u8f03\u3057\u3001\u3082\u3057\u540c\u3058\uff08\u3064\u307e\u308a\u3059\u3079\u3066\u89e3\u7b54\u6e08\u307f\uff09\u306e\u5834\u5408\u3068\u305d\u3046\u3067\u306a\u3044\u5834\u5408\u306e\u5206\u5c90\u3092<code>if<\/code>\u5206\u3067\u4f5c\u308a\u307e\u3059\u3002<\/p>\n<p>\u3082\u3057\u307e\u3060\u6b21\u306e\u8cea\u554f\u304c\u6b8b\u3063\u3066\u3044\u308b\u5834\u5408\u306f\u3001<code>questionIndex<\/code>\u306b<code>1<\/code>\u8ffd\u52a0\u3059\u308b\u306e\u3067\u3001\u6b21\u306e\u30af\u30a4\u30ba\u304c\u81ea\u52d5\u7684\u306b\u8868\u793a\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u203b \u3061\u306a\u307f\u306b<code>methods<\/code>\u3068<code>computed<\/code>\u306e\u9055\u3044\u306f\u904e\u53bb\u8a18\u4e8b\u3001<a href=\"https:\/\/blog.capilano-fw.com\/?p=485\">Vue\u306e\u300cmethods\u300d\u3068\u300ccomputed\u300d\u306e\u9055\u3044<\/a>\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2>\u30af\u30a4\u30ba\u304c\u5b8c\u4e86\u3057\u305f\u3068\u304d\u306e\u51e6\u7406\u3092\u3064\u304f\u308b<\/h2>\n<p>\u3067\u306f\u6700\u5f8c\u306b\u5168\u3066\u306e\u8cea\u554f\u306b\u7b54\u3048\u305f\u3068\u304d\u306e\u51e6\u7406\u3092\u4f5c\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>addAnswer: function(index) {\r\n\r\n    this.answers.push(index);\r\n\r\n    if(this.questions.length == this.answers.length) {\r\n\r\n        <strong>var correctCount = 0;<\/strong>\r\n\r\n<strong>        for(var i in this.answers) {<\/strong>\r\n\r\n<strong>            var answer = this.answers[i];<\/strong>\r\n\r\n<strong>            if(answer == this.questions[i].answer) {<\/strong>\r\n\r\n<strong>                correctCount++;<\/strong>\r\n\r\n<strong>            }<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n\r\n<strong>        alert(correctCount +'\u554f\u6b63\u89e3\u3067\u3059\uff01');<\/strong>\r\n\r\n    } else {\r\n\r\n        \/\/ \u7701\u7565\r\n\r\n    }\r\n\r\n}<\/pre>\n<p>\u4e2d\u8eab\u3068\u3057\u3066\u306f\u3001\u89e3\u7b54\u30c7\u30fc\u30bf<code>answers<\/code>\u3092\u30eb\u30fc\u30d7\u3055\u305b\u3066\u3072\u3068\u3064\u305a\u3064\u89e3\u7b54\u3092\u53d6\u5f97\u3057\u3001\u6b63\u89e3\u30c7\u30fc\u30bf\u3092\u6bd4\u8f03\u3057\u307e\u3059\u3002\u305d\u3057\u3066\u3001\u3053\u306e\uff12\u3064\u304c\u540c\u3058\uff08\u3064\u307e\u308a\u6b63\u89e3\uff09\u306a\u3089<code>correctCount<\/code>\u306b<code>1<\/code>\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u5168\u3066\u306e\u6b63\u89e3\u30c1\u30a7\u30c3\u30af\u304c\u7d42\u308f\u3063\u305f\u3089<code>alert()<\/code>\u3092\u4f7f\u3063\u3066\u300c\u25cb\u554f\u6b63\u89e3\u3067\u3059\uff01\u300d\u3068\u8868\u793a\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h1>\u304a\u307e\u3051<\/h1>\n<p>\u3069\u3046\u3057\u3088\u3046\u304b\u60a9\u3093\u3060\u306e\u3067\u3059\u304c\u3001\u521d\u5fc3\u8005\u5411\u3051\u3068\u3044\u3046\u3053\u3068\u3067\u4eca\u56de\u306f\u7d50\u679c\u306e\u8868\u793a\u3092\u6b63\u89e3\u6570\u3060\u3051\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u305b\u3063\u304b\u304f\u3053\u3053\u307e\u3067\u4f5c\u3063\u305f\u306e\u3067\u3001\u7d50\u679c\u306f\u300c\u3069\u306e\u554f\u984c\u304c\u6b63\u89e3\u3067\u3001\u6b63\u3057\u3044\u7b54\u3048\u306f\u4f55\u3060\u3063\u305f\u306e\u304b\uff1f\u300d\u3092\u8868\u793a\u3059\u308b\u3088\u3046\u306b\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002\uff08\u305d\u306e\u305f\u3081\u3001\u4eca\u56de\u6559\u6750\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306f\u3001\u30b7\u30e7\u30fc\u30c8\u30fb\u30d0\u30fc\u30b8\u30e7\u30f3\u3068\u30d5\u30eb\u30fb\u30d0\u30fc\u30b8\u30e7\u30f3\u306e\uff12\u3064\u304c\u3042\u308a\u307e\u3059\uff09<\/p>\n<p>\u3067\u306f\u3001\u307e\u305a<code>computed<\/code>\u306b<code>completed<\/code>\u3068\u3044\u3046\u30af\u30a4\u30ba\u306e\u89e3\u7b54\u304c\u3059\u3079\u3066\u5b8c\u4e86\u3057\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u304c\u5206\u304b\u308b\u7591\u4f3c\u5909\u6570\u3092\u3064\u304f\u308a\u307e\u3059\u3002<\/p>\n<pre>computed: {\r\n    \r\n    \/\/ \u7701\u7565\r\n\r\n<strong>    completed: function() {<\/strong>\r\n\r\n<strong>        return (this.questions.length == this.answers.length);<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n}<\/pre>\n<p>\u305d\u3057\u3066\u3001\u5148\u307b\u3069\u3064\u304f\u3063\u305f<code>addAnswer()<\/code>\u306e<code>alert()<\/code>\u3092\u524a\u9664\u3057\u307e\u3059\u3002<\/p>\n<pre>addAnswer: function(index) {\r\n\r\n<strong>    this.answers.push(index);<\/strong>\r\n\r\n<strong>    if(!this.completed) {<\/strong>\r\n\r\n<strong>        this.questionIndex++;<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n\r\n}<\/pre>\n<p>\u3055\u3089\u306b\u3001HTML\u306f\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>&lt;!-- \u30af\u30a4\u30ba\u3092\u8868\u793a\u3059\u308b\u90e8\u5206 --&gt;\r\n&lt;div class=\"offset-3 col-6\" <strong>v-if=\"!completed\"<\/strong>&gt;\r\n    &lt;div class=\"card\"&gt;\r\n        &lt;div class=\"card-body\"&gt;\r\n            &lt;p class=\"badge badge-dark\"&gt;\u7b2c {{ (questionIndex+1) }} \u554f&lt;\/p&gt;\r\n            &lt;br&gt;\r\n            &lt;h4 class=\"card-title\"&gt;{{ currentQuestion.question }}&lt;\/h4&gt;\r\n            &lt;hr&gt;\r\n            &lt;button\r\n                type=\"button\"\r\n                class=\"btn btn-primary btn-lg btn-block text-left\"\r\n                v-for=\"(answer,index) in currentQuestion.answers\"\r\n                @click=\"addAnswer(index)\"&gt;{{ (index+1) }}. {{ answer }}&lt;\/button&gt;\r\n        &lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n&lt;\/div&gt;\r\n\r\n&lt;!-- \u7d50\u679c\u8868\u793a\u3059\u308b\u90e8\u5206 --&gt;\r\n&lt;div class=\"offset-3 col-6\" <strong>v-if=\"completed\"<\/strong>&gt;\r\n    &lt;div class=\"card\"&gt;\r\n        &lt;div class=\"card-body\"&gt;\r\n            &lt;p class=\"badge badge-dark\"&gt;\u7d50\u679c&lt;\/p&gt;\r\n            &lt;div <strong>v-for=\"(question,index) in this.questions\"<\/strong>&gt;\r\n                &lt;h4 class=\"card-title\"&gt;{{ question.question }}&lt;\/h4&gt;\r\n                &lt;ul&gt;\r\n                    &lt;li v-for=\"answer in question.answers\"&gt;{{ answer }}&lt;\/li&gt;\r\n                &lt;\/ul&gt;\r\n                <strong>&lt;span v-if=\"question.answer == answers[index]\"&gt;\u6b63\u89e3 &amp;#x1F44D;&lt;\/span&gt;<\/strong>\r\n<strong>                &lt;span v-else&gt;\u4e0d\u6b63\u89e3 &amp;#x1F622;&lt;br&gt;\u6b63\u89e3\u306f\u300c{{ question.answers[question.answer] }}\u300d\u3067\u3057\u305f\u3002&lt;\/span&gt;<\/strong>\r\n                &lt;hr&gt;\r\n            &lt;\/div&gt;\r\n        &lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n&lt;\/div&gt;<\/pre>\n<p>\u3053\u3053\u3067\u91cd\u8981\u306a\u306e\u304c\u3001<code>complted<\/code>\u304c<code>true<\/code>\u304b<code>false<\/code>\u304b\u3067\u8868\u793a\u5185\u5bb9\u3092\u5207\u308a\u66ff\u3048\u3066\u3044\u308b\u3053\u3068\u3067\u3059\u3002\u3064\u307e\u308a\u3001<strong>\u89e3\u7b54\u4e2d\u306f\u30af\u30a4\u30ba\u306e\u307f\u8868\u793a\u3057\u3001\u89e3\u7b54\u304c\u5b8c\u4e86\u3057\u305f\u3089\u7d50\u679c\u3060\u3051\u3092\u8868\u793a\u3059\u308b<\/strong>\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u7d50\u679c\u30d6\u30ed\u30c3\u30af\u3067\u306f\u5404\u8cea\u554f\u3068\u7b54\u3048\u3092\u8868\u793a\u3057\u3001\u6b63\u89e3\u3057\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u3067\u8868\u793a\u3092\u5207\u308a\u66ff\u3048\u3066\u3044\u307e\u3059\u3002<\/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-2507\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/quiz_4.png\" alt=\"\" width=\"646\" height=\"743\" \/><\/p>\n<p>\u4eca\u56de\u306f\u4ee5\u4e0a\u3067\u3059\u3002<br \/>\n\u304a\u75b2\u308c\u69d8\u3067\u3057\u305f\uff01<\/p>\n<h1>\u30c7\u30e2\u30da\u30fc\u30b8\u3092\u7528\u610f\u3057\u307e\u3057\u305f<\/h1>\n<p>\uff13\u629e\u30af\u30a4\u30ba\u3092\u8a66\u3057\u3066\u3044\u305f\u3060\u3051\u308b\u3088\u3046\u3001<a href=\"https:\/\/demo-laravel52.capilano-fw.com\/vue_quiz\" target=\"_blank\" rel=\"noopener\">\u30c7\u30e2\u30da\u30fc\u30b8<\/a>\u3092\u7528\u610f\u3057\u307e\u3057\u305f\u3002<br \/>\n\u305c\u3072\u697d\u3057\u3093\u3067\u304f\u3060\u3055\u3044\u266a<\/p>\n<h1>\u6559\u6750\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\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<p>\u203b <code>short.html<\/code>\u304c\u77ed\u3044\u30d0\u30fc\u30b8\u30e7\u30f3\u3067\u3001<code>full.html<\/code>\u304c\u7d50\u679c\u8868\u793a\u307e\u3067\u3059\u308b\u30d5\u30eb\u30d0\u30fc\u30b8\u30e7\u30f3\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<a  data-e-Disable-Page-Transition=\"true\" class=\"download-link\" title=\"\" href=\"https:\/\/blog.capilano-fw.com?download=2508&amp;tmstv=1777532620\" rel=\"nofollow\" id=\"download-link-2508\" data-redirect=\"false\" >\n\tVueJS \u3067\uff13\u629e\u30af\u30a4\u30ba\u30b2\u30fc\u30e0\u3092\u3064\u304f\u308b<\/a>\n\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3053\u306e\u30d6\u30ed\u30b0\u3067\u306f\u3067\u304d\u308b\u3060\u3051\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u697d\u3057\u3055\u3092\u591a\u304f\u306e\u4eba\u306b\u77e5\u3063\u3066\u3082\u3089\u3044\u305f\u3044\u3068\u3044\u3046\u6c17\u6301\u3061\u3067\u516c\u958b\u3057\u3066\u3044\u308b\u8a18\u4e8b\u3082\u591a\u304f\u3042\u308b\u306e\u3067\u3059\u304c\u3001\u3069\u3046\u3057\u3066\u3082\u6271\u3063\u3066\u3044\u308b\u306e\u304c\u30d7 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=2499\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u521d\u5fc3\u8005\u5411\u304d\uff01VueJS \u3067\uff13\u629e\u30af\u30a4\u30ba\u30b2\u30fc\u30e0\u3092\u3064\u304f\u3063\u3066\u307f\u3088\u3046&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":2501,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,97],"tags":[115],"class_list":["post-2499","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vue-js","category-97","tag-115"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/2499","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=2499"}],"version-history":[{"count":5,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/2499\/revisions"}],"predecessor-version":[{"id":2519,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/2499\/revisions\/2519"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/2501"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}