{"id":8347,"date":"2020-12-07T07:00:26","date_gmt":"2020-12-06T22:00:26","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=8347"},"modified":"2020-12-02T06:08:41","modified_gmt":"2020-12-01T21:08:41","slug":"vue-datalist-%e3%81%a7%e7%b0%a1%e5%8d%98%e3%81%ab%e5%85%a5%e5%8a%9b%e5%80%99%e8%a3%9c%e3%82%92%e6%9c%89%e5%8a%b9%e3%81%ab%e3%81%99%e3%82%8b%ef%bc%88%e3%83%87%e3%83%a2%e3%83%9a%e3%83%bc%e3%82%b8","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=8347","title":{"rendered":"Vue + datalist \u3067\u7c21\u5358\u306b\u5165\u529b\u5019\u88dc\u3092\u6709\u52b9\u306b\u3059\u308b\uff08\u30c7\u30e2\u30da\u30fc\u30b8\u3042\u308a\uff09"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001<code>Vue 3<\/code>\u304c\u767b\u5834\u3057\u3066\u304b\u3089\u5c11\u3057\u6642\u9593\u304c\u7d4c\u3061\u307e\u3057\u305f\u3002\u57fa\u672c\u7684\u306b\u306f\u524d\u56de\u30d0\u30fc\u30b8\u30e7\u30f3\u3068\u540c\u3058\u69cb\u6210\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u79fb\u884c\u306f\u305d\u308c\u307b\u3069\u624b\u9593\u53d6\u308b\u3053\u3068\u306f\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u203b \u305f\u3060\u3057\u3001<code>Laravel + npm<\/code>\u3067<code>Vue 3<\/code>\u3092\u4f7f\u304a\u3046\u3068\u3059\u308b\u3068\u30b7\u30f3\u30b0\u30eb\u30fb\u30d5\u30a1\u30a4\u30eb\u30fb\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304c\u3046\u307e\u304f\u51e6\u7406\u3067\u304d\u306a\u3044\u306e\u3067\u500b\u4eba\u7684\u306b\u306f\u30ac\u30f3\u30ac\u30f3\u4f7f\u3063\u3066\u307e\u305b\u3093\ud83d\udca7\u3053\u308c\u306f\u3001<code>Laravel Mix 6<\/code>\u3067\u5bfe\u5fdc\u3059\u308b\u3068\u306e\u3053\u3068\u3067\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u305d\u3093\u306a<code>Vue<\/code>\u3067\u4eca\u56de\u4f5c\u3063\u3066\u307f\u308b\u306e\u304c\u3001<\/p>\n<p><strong style=\"font-size: 35px;\">\u5165\u529b\u5019\u88dc\u304b\u3089\u9078\u629e\u3067\u304d\u308b\u6a5f\u80fd<\/strong><\/p>\n<p>\u3067\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u6b21\u306e\u3088\u3046\u306a\u30ab\u30f3\u30b8\u3067\u3059\u306d\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8348\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/12\/vue_datalist_1.png\" alt=\"\" width=\"210\" height=\"237\" \/><\/p>\n<p>\u3068\u3044\u3046\u306e\u3082\u3001\u300c<strong>\u3081\u3093\u3069\u3046\u306a\u5165\u529b\u3092\u3067\u304d\u308b\u3060\u3051\u7701\u7565\u3057\u305f\u3044<\/strong>\u300d\u3068\u3044\u3046\u306e\u306f\u8ab0\u3067\u3082\u8981\u671b\u304c\u9ad8\u3044\u3067\u3057\u3087\u3046\u3057\u3001\u7279\u306b\u6bce\u65e5\u306e\u696d\u52d9\u3067\u4f7f\u3046\u5834\u5408\u306f\u300c<strong>\u307e\u305f\u304a\u3093\u306a\u3058\u5165\u529b\u304b\u3088\u30fb\u30fb\u30fb<\/strong>\u300d\u3068\u3046\u3093\u3056\u308a\u3059\u308b\u306f\u305a\u3060\u304b\u3089\u3067\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u305d\u3093\u306a\u3068\u304d\u306b\u601d\u3044\u51fa\u3057\u305f\u306e\u304c<code>HTML 5<\/code>\u306e<code>&lt;datalist&gt;&lt;\/datalist&gt;<\/code>\u3067\u3059\u3002\uff08\u3053\u308c\u3001\u3059\u3063\u304b\u308a\u5fd8\u308c\u3066\u307e\u3057\u305f\ud83d\ude02\uff09<\/p>\n<p>\u5165\u529b\u5019\u88dc\u3068\u8a00\u3048\u3070\u3001\u305d\u306e\u6614\u306f\u00a0<a href=\"https:\/\/select2.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">select2<\/a> \u306a\u3069JS\u30d1\u30c3\u30b1\u30fc\u30b8\u3067\u5b9f\u88c5\u3057\u3066\u3044\u307e\u3057\u305f\u304c\u3001\u306a\u3093\u3068\u4eca\u306f<code>HTML<\/code>\u3060\u3051\u3067OK\u306a\u3093\u3067\u3059\u306d\u3002<\/p>\n<p>\u305d\u3053\u3067\u2757<\/p>\n<p>\u4eca\u56de\u306fVue\uff08\u30d0\u30fc\u30b8\u30e7\u30f3<code>3<\/code>&amp;<code>2<\/code>\uff09\u3067\u7c21\u5358\u306b<code>datalist<\/code>\u304c\u4f7f\u3048\u308b\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3092\u3064\u304f\u3063\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u30e6\u30fc\u30b6\u30d3\u30ea\u30c6\u30a3\u306e\u305f\u3081\u306b\u8a66\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\ud83d\ude0a\u2728<br \/>\n\uff08\u6700\u5f8c\u306b\u5b9f\u969b\u958b\u767a\u3057\u305f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u4e00\u5f0f\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3067\u304d\u307e\u3059\u3088\ud83d\udc4d\uff09<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3344 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_22.png\" alt=\"\" width=\"320\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_22.png 320w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_22-150x150.png 150w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_22-300x300.png 300w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_22-100x100.png 100w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/>\u300c\u30eb\u30d1\u30f3\u4e09\u4e16 Part\uff11\u898b\u3066\u307e\u3059\u3002<br \/>\n\u3084\u3063\u3071\u308a\u9762\u767d\u3044\u3067\u3059\u306d\u300d<\/p>\n<p><strong>\u958b\u767a\u74b0\u5883\uff1a<\/strong> Vue 3.0.3\u3001Vue 2.6.12<\/p>\n<h1>\u3084\u308a\u305f\u3044\u3053\u3068<\/h1>\n<p>\u3042\u308b<code>&lt;Input&gt;<\/code>\u30bf\u30b0\u306b\u914d\u5217\u30c7\u30fc\u30bf\u3092\u30bb\u30c3\u30c8\u3059\u308b\u3060\u3051\u3067<code>datalist<\/code>\u304c\u6a5f\u80fd\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001\u4eca\u56de\u306f<code>Vue<\/code>\u3067\u72ec\u81ea\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308b\u300c<strong>\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6<\/strong>\u300d\u3092\u4f7f\u3063\u3066\u5b9f\u88c5\u3057\u307e\u3059\u3002<\/p>\n<p>\u30b5\u30f3\u30d7\u30eb\u306f\u3053\u3093\u306a\u30ab\u30f3\u30b8\u3067\u3059\u3002<\/p>\n<pre>&lt;input type=\"text\" <strong>v-data-list=\"values\"<\/strong>&gt;<\/pre>\n<p>\u306a\u304a\u3001\u4eca\u56de\u306f\u30b3\u30fc\u30c9\u91cf\u304c\u305d\u308c\u307b\u3069\u591a\u304f\u306a\u3044\u306e\u3067<code>Vue 3<\/code>\u3060\u3051\u3067\u306a\u304f\u3001<code>Vue 2<\/code>\u3067\u306e\u5b9f\u88c5\u3082\u5408\u308f\u305b\u3066\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u6a5f\u4f1a\u306b\u3001\u30d0\u30fc\u30b8\u30e7\u30f3\uff12\u3068\uff13\u306e\u9055\u3044\u3092\u6bd4\u3079\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u306d\ud83d\udc4d<\/p>\n<h1>datalist\u306e\u4f7f\u3044\u65b9<\/h1>\n<p>\u307e\u305a\u3001<code>&lt;input&gt;<\/code>\u306b\u5165\u529b\u5019\u88dc\u3092\u8868\u793a\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b<code>&lt;datalist&gt;<\/code>\u30bf\u30b0\u306e\u4f7f\u3044\u65b9\u3067\u3059\u3002\uff08\u3054\u5b58\u77e5\u306e\u65b9\u306f\u6b21\u307e\u3067\u98db\u3070\u3057\u3066\u304f\u3060\u3055\u3044\uff09<\/p>\n<pre>&lt;!-- \u5165\u529b\u90e8\u5206 --&gt;\r\n<strong>&lt;input type=\"text\" list=\"fruits\"&gt;<\/strong>\r\n\r\n&lt;!-- \u30ea\u30b9\u30c8\u90e8\u5206 --&gt;\r\n<strong>&lt;datalist id=\"fruits\"&gt;<\/strong>\r\n<strong>    &lt;option value=\"\u30ea\u30f3\u30b4\"&gt;<\/strong>\r\n<strong>    &lt;option value=\"\u30df\u30ab\u30f3\"&gt;<\/strong>\r\n<strong>    &lt;option value=\"\u30d0\u30ca\u30ca\"&gt;<\/strong>\r\n<strong>&lt;\/datalist&gt;<\/strong><\/pre>\n<p>\u3053\u3053\u3067\u91cd\u8981\u306a\u306e\u304c\u3001<code>fruits<\/code>\u306e\u90e8\u5206\u3067\u3059\u3002<\/p>\n<p><code>&lt;input&gt;<\/code>\u3067\u306f<code>list=\"****\"<\/code>\u306e\u4e2d\u306b\u3001\u305d\u3057\u3066<code>&lt;datalist&gt;<\/code>\u3067\u306f<code>id=\"****\"<\/code>\u306b\u305d\u308c\u305e\u308c\u30bb\u30c3\u30c8\u3057\u3001\u30da\u30a2\u3092\u3064\u304f\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001<code>&lt;input&gt;<\/code>\u306b\u30d5\u30a9\u30fc\u30ab\u30b9\u304c\u5f53\u305f\u308b\u3068\uff08\u5165\u529b\u72b6\u614b\u306b\u306a\u308b\u3068\uff09\u3001<code>&lt;datalist&gt;<\/code>\u306e\u90e8\u5206\u304c\u8868\u793a\u3055\u308c\u3001\u5404\u9805\u76ee\u304c\u9078\u629e\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3057\u304b\u3082\u3001<code>&lt;datalist&gt;<\/code>\u306f\u3068\u3066\u3082\u6709\u80fd\u3067\u3001\u4f8b\u3048\u3070\u4e0a\u306e\u5834\u5408\u300c\u30b4\u300d\u3068\u5165\u529b\u3059\u308b\u3068\u305d\u306e\u6587\u5b57\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u300c<strong>\u30ea\u30f3\u30b4<\/strong>\u300d\u3060\u3051\u306b\u7d5e\u308a\u8fbc\u3093\u3067\u304f\u308c\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8352\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/12\/vue_datalist_2.png\" alt=\"\" width=\"208\" height=\"92\" \/><\/p>\n<p>\u3061\u306a\u307f\u306b\u3001<code>datalist<\/code>\u306b<code>label=\"***\"<\/code>\u3092\u3064\u3051\u308b\u3068\u3061\u3087\u3063\u3068\u3057\u305f\u8aac\u660e\u66f8\u304d\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre>&lt;datalist id=\"reservation_dates\"&gt;\r\n    &lt;option <strong>label=\"\u4eca\u65e5\"<\/strong>&gt;20020-01-01&lt;\/option&gt;\r\n    &lt;option <strong>label=\"\u660e\u65e5\"<\/strong>&gt;20020-01-02&lt;\/option&gt;\r\n    &lt;option <strong>label=\"\u660e\u5f8c\u65e5\"<\/strong>&gt;20020-01-03&lt;\/option&gt;\r\n&lt;\/datalist&gt;<\/pre>\n<p>\u5b9f\u969b\u306e\u8868\u793a\u306f\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8353\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/12\/vue_datalist_3.png\" alt=\"\" width=\"181\" height=\"185\" \/><\/p>\n<p>\u4eca\u56de\u306f\u305b\u3063\u304b\u304f\u306a\u306e\u3067\u3001\u3053\u306e<code>label<\/code>\u3082\u72ec\u81ea\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3067\u4f7f\u3048\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001\u5b9f\u969b\u306b\u3084\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u2757<\/p>\n<h1>Vue 3\u3067datalist\u5165\u529b\u5019\u88dc\u3092\u6709\u52b9\u306b\u3059\u308b<\/h1>\n<p>\u4ee5\u4e0b\u304c\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u306b\u306a\u308a\u307e\u3059\u3002\uff08<a href=\"http:\/\/demo-laravel8x.capilano-fw.com\/vue3_datalist\" target=\"_blank\" rel=\"noopener noreferrer\">\u30c7\u30e2\u30da\u30fc\u30b8\u306f\u3053\u3061\u3089<\/a>\uff09<\/p>\n<pre>&lt;html&gt;\r\n&lt;body&gt;\r\n&lt;div id=\"app\"&gt;\r\n    <strong>&lt;!-- \u2462 \u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3092\u4f7f\u3046 --&gt;<\/strong>\r\n<strong>    \u3010\u6587\u5b57\u5217\u3011&lt;br&gt;<\/strong>\r\n<strong>    &lt;input type=\"text\" v-data-list=\"colors\"&gt;<\/strong>\r\n<strong>    &lt;br&gt;&lt;br&gt;<\/strong>\r\n<strong>    \u3010\u6570\u5024\u3011&lt;br&gt;<\/strong>\r\n<strong>    &lt;input type=\"text\" v-data-list=\"numbers\"&gt;<\/strong>\r\n<strong>    &lt;br&gt;&lt;br&gt;<\/strong>\r\n<strong>    \u3010\u65e5\u4ed8\u3011&lt;br&gt;<\/strong>\r\n<strong>    &lt;input type=\"date\" v-data-list=\"dates\"&gt;<\/strong>\r\n&lt;\/div&gt;\r\n&lt;script src=\"https:\/\/unpkg.com\/vue@3.0.3\/dist\/vue.global.prod.js\"&gt;&lt;\/script&gt;\r\n&lt;script&gt;\r\n\r\n    <strong>\/\/ \u2460 \u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3092\u5b9a\u7fa9\u3059\u308b<\/strong>\r\n<strong>    const dataListDirective = {<\/strong>\r\n<strong>        mounted(el, binding) {<\/strong>\r\n\r\n<strong>            const listValues = binding.value;<\/strong>\r\n<strong>            const randomKey = 'datalist-'+ Math.random().toString(36).substring(7);<\/strong>\r\n<strong>            let dataList = document.createElement('datalist');<\/strong>\r\n<strong>            dataList.setAttribute('id', randomKey);<\/strong>\r\n<strong>            el.setAttribute('list', randomKey)<\/strong>\r\n\r\n<strong>            for(let listValue of listValues) {<\/strong>\r\n\r\n<strong>                let option = document.createElement('option');<\/strong>\r\n\r\n<strong>                if(typeof listValue === 'object') { \/\/ \u30e9\u30d9\u30eb\u4ed8\u304d\u306e\u5834\u5408<\/strong>\r\n\r\n<strong>                    option.label = listValue.label;<\/strong>\r\n<strong>                    option.value = listValue.value;<\/strong>\r\n\r\n<strong>                } else {<\/strong>\r\n\r\n<strong>                    option.value = listValue;<\/strong>\r\n\r\n<strong>                }<\/strong>\r\n\r\n<strong>                dataList.appendChild(option);<\/strong>\r\n\r\n<strong>            }<\/strong>\r\n\r\n<strong>            document.querySelector('body').appendChild(dataList);<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n<strong>    };<\/strong>\r\n\r\n    Vue.createApp({\r\n        data() {\r\n            return {\r\n                colors: ['\u8d64', '\u9752', '\u9ec4\u8272', '\u9ed2','\u767d'],\r\n                numbers: [500, 1000, 1500],\r\n                dates: [\r\n                    { value: '20020-01-01', label: '\u4eca\u65e5' },\r\n                    { value: '20020-01-02', label: '\u660e\u65e5' },\r\n                    { value: '20020-01-03', label: '\u660e\u5f8c\u65e5' },\r\n                ]\r\n            }\r\n        }\r\n    })\r\n    .<strong>directive('data-list', dataListDirective) \/\/ \u2461 \u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3092\u6709\u52b9\u306b\u3059\u308b<\/strong>\r\n    .mount('#app');\r\n\r\n&lt;\/script&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\u3067\u306f\u3001\u4e2d\u8eab\u3092\u3072\u3068\u3064\u305a\u3064\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p><strong>\u2460 \u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3092\u5b9a\u7fa9\u3059\u308b<\/strong><\/p>\n<p>\u307e\u305a<code>JavaScript<\/code>\u90e8\u5206\u306b\u300c\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u300d\u306e\u672c\u4f53\u3092\u3064\u304f\u308a\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u4e2d\u3067\u3084\u3063\u3066\u3044\u308b\u624b\u9806\u306f\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<ol>\n<li>\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u306b\u30bb\u30c3\u30c8\u3055\u308c\u305f\u5165\u529b\u5019\u88dc\uff08\u914d\u5217\u30c7\u30fc\u30bf\uff09\u3092\u53d6\u5f97<\/li>\n<li>\u30e9\u30f3\u30c0\u30e0\u306a\u6587\u5b57\u5217\u3092\u3064\u304f\u3063\u3066\u3001\u305d\u308c\u305e\u308c &lt;input&gt; \u3068 &lt;datalist&gt; \u306b\u30bb\u30c3\u30c8<\/li>\n<li>datalist \u306b\u5165\u529b\u5019\u88dc\u3068\u306a\u308b\u6587\u5b57\u5217\u3092\u30bb\u30c3\u30c8 \u203b<\/li>\n<li>&lt;body&gt; \u30bf\u30b0\u306b &lt;datalist&gt; \u3092\u633f\u5165<\/li>\n<li>\u5b8c\u4e86\uff01<\/li>\n<\/ol>\n<p>\u203b \u306a\u304a\u3001\u30bb\u30c3\u30c8\u3055\u308c\u305f\u30c7\u30fc\u30bf\u304c\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\uff08\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u914d\u5217\uff09\u306e\u5834\u5408\u306f\u81ea\u52d5\u7684\u306b<code>label<\/code>\u3082\u30bb\u30c3\u30c8\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre><strong>[<\/strong>\r\n<strong>    { value: '20020-01-01', label: '\u4eca\u65e5' },<\/strong>\r\n<strong>    { value: '20020-01-02', label: '\u660e\u65e5' },<\/strong>\r\n<strong>    { value: '20020-01-03', label: '\u660e\u5f8c\u65e5' },<\/strong>\r\n<strong>]<\/strong><\/pre>\n<p>\u306a\u304a\u3001\u30e9\u30f3\u30c0\u30e0\u306a\u6587\u5b57\u5217\u3092\u3064\u304f\u3063\u3066\u3044\u308b\u306e\u306f\u3001<code>v-data-list<\/code>\u304c\u8907\u6570\u547c\u3073\u51fa\u3055\u308c\u3066\u3082<code>id<\/code>\u304c\u91cd\u8907\u3057\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u3067\u3059\u3002<\/p>\n<p><strong>\u2461 \u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3092\u6709\u52b9\u306b\u3059\u308b<\/strong><\/p>\n<p>\u5148\u307b\u3069\u3064\u304f\u3063\u305f<code>dataListDirective<\/code>\u306f\u3001\u5358\u4f53\u3067\u306f\u5358\u306a\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306a\u306e\u3067\u3001\u3053\u308c\u3092\u6709\u52b9\u306b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre>.<strong>directive('data-list', dataListDirective)<\/strong><\/pre>\n<p>\u203b\u306a\u304a\u3001<code>v-<\/code>\u306e\u90e8\u5206\u306f\u81ea\u52d5\u3067\u4ed8\u4e0e\u3055\u308c\u308b\u306e\u3067\u7b2c\u4e00\u5f15\u6570\u306f\u3001<code>data-list<\/code>\u306e\u307f\u3067OK\u3067\u3059\u3002<\/p>\n<p><strong>\u2462 \u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3092\u4f7f\u3046<\/strong><\/p>\n<p>\u305d\u3057\u3066\u6700\u5f8c\u306b<code>v-data-list<\/code>\u306e\u4f7f\u3044\u65b9\u3067\u3059\u3002<\/p>\n<p>\u3053\u3053\u306f\u3001\u8868\u793a\u3057\u305f\u3044\u5165\u529b\u5019\u88dc\uff08\u914d\u5217\uff09\u3092<code>v-data-list=\"****\"<\/code>\u306e\u4e2d\u306b\u5165\u308c\u3066\u3042\u3052\u308b\u3060\u3051\u3067OK\u3067\u3059\u3002<\/p>\n<pre>&lt;input type=\"text\" <strong>v-data-list=\"colors\"<\/strong>&gt;<\/pre>\n<p>\u914d\u5217\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b<code>Vue<\/code>\u672c\u4f53\u3067\u5b9a\u7fa9\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre>Vue.createApp({\r\n    data() {\r\n        return {\r\n            <strong>colors: ['\u8d64', '\u9752', '\u9ec4\u8272', '\u9ed2','\u767d'],<\/strong>\r\n<strong>            numbers: [500, 1000, 1500],<\/strong>\r\n<strong>            dates: [<\/strong>\r\n<strong>                { value: '20020-01-01', label: '\u4eca\u65e5' },<\/strong>\r\n<strong>                { value: '20020-01-02', label: '\u660e\u65e5' },<\/strong>\r\n<strong>                { value: '20020-01-03', label: '\u660e\u5f8c\u65e5' },<\/strong>\r\n<strong>            ]<\/strong>\r\n        }\r\n    }\r\n})<\/pre>\n<p>\u26a0\u00a0<code>Vue 2<\/code>\u3068\u306f\u9055\u3044\u3001<code>data<\/code>\u306f\u95a2\u6570\u3067\u6307\u5b9a\u3059\u308b\u3088\u3046\u5909\u66f4\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u306a\u304a\u3001\u6587\u5b57\u5217\u3060\u3084\u6570\u5024\u3060\u3051\u3067\u306a\u304f\u3001\u65e5\u4ed8\u9078\u629e\u306e<code>&lt;input type=\"date\"&gt;<\/code>\u3067\u3082\u4f7f\u3048\u307e\u3059\u3002\u30ca\u30a4\u30b9\u3067\u3059\u306d\ud83d\udc4d<\/p>\n<h1>Vue 2\u3067datalist\u5165\u529b\u5019\u88dc\u3092\u6709\u52b9\u306b\u3059\u308b<\/h1>\n<p>\u3067\u306f\u3001<code>Vue 2<\/code>\u306e\u65b9\u3067\u3082\u3064\u304f\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002\uff08<a href=\"http:\/\/demo-laravel8x.capilano-fw.com\/vue2_datalist\" target=\"_blank\" rel=\"noopener noreferrer\">\u30c7\u30e2\u30da\u30fc\u30b8\u306f\u3053\u3061\u3089<\/a>\uff09<br \/>\n\u3068\u306f\u8a00\u3063\u3066\u3082\u3001\u307b\u307c\u30bb\u30c3\u30c8\u306e\u4ed5\u65b9\u304c\u9055\u3046\u3060\u3051\u3067\u3059\u3002<\/p>\n<pre>&lt;html&gt;\r\n&lt;body&gt;\r\n&lt;div id=\"app\"&gt;\r\n    &lt;!-- \u2462 \u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3092\u4f7f\u3046 --&gt;\r\n    \u3010\u6587\u5b57\u5217\u3011&lt;br&gt;\r\n    &lt;input type=\"text\" v-data-list=\"colors\"&gt;\r\n    &lt;br&gt;&lt;br&gt;\r\n    \u3010\u6570\u5024\u3011&lt;br&gt;\r\n    &lt;input type=\"text\" v-data-list=\"numbers\"&gt;\r\n    &lt;br&gt;&lt;br&gt;\r\n    \u3010\u65e5\u4ed8\u3011&lt;br&gt;\r\n    &lt;input type=\"date\" v-data-list=\"dates\"&gt;\r\n&lt;\/div&gt;\r\n&lt;script src=\"https:\/\/cdn.jsdelivr.net\/npm\/vue@2.6.12\/dist\/vue.min.js\"&gt;&lt;\/script&gt;\r\n&lt;script&gt;\r\n\r\n    \/\/ \u2460 \u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3092\u5b9a\u7fa9\u3059\u308b\r\n    const dataListDirective = {\r\n        <strong>inserted<\/strong>(el, binding) {\r\n\r\n            \/\/ \u7701\u7565\uff1a Vue 3\u30d0\u30fc\u30b8\u30e7\u30f3\u3068\u540c\u3058\u3067\u3059\r\n\r\n        }\r\n    };\r\n\r\n    new Vue({\r\n        el: '#app',\r\n        <strong>directives: { 'data-list': dataListDirective }<\/strong>, \/\/ \u2461 \u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3092\u6709\u52b9\u306b\u3059\u308b\r\n        data: {\r\n            colors: ['\u8d64', '\u9752', '\u9ec4\u8272', '\u9ed2','\u767d'],\r\n            numbers: [500, 1000, 1500],\r\n            dates: [\r\n                { value: '20020-01-01', label: '\u4eca\u65e5' },\r\n                { value: '20020-01-02', label: '\u660e\u65e5' },\r\n                { value: '20020-01-03', label: '\u660e\u5f8c\u65e5' },\r\n            ]\r\n        }\r\n    });\r\n\r\n&lt;\/script&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\u306a\u304a\u3001\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u5185\u306e<code>inserted<\/code>\u306f<code>Vue 3<\/code>\u3067\u3044\u3046\u3068\u3053\u308d\u306e<code>mounted<\/code>\u306b\u76f8\u5f53\u3057\u307e\u3059\u3002<\/p>\n<p><strong>\u3010\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u5185\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u5909\u5316\u3011<\/strong><\/p>\n<table border=\"1\">\n<thead style=\"background-color: #f9f9f9;\">\n<tr>\n<th>Vue 2<\/th>\n<th>Vue 3<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>bind<\/td>\n<td>beforeMount<\/td>\n<\/tr>\n<tr>\n<td>inserted<\/td>\n<td>mounted<\/td>\n<\/tr>\n<tr>\n<td>componentUpdated<\/td>\n<td>updated<\/td>\n<\/tr>\n<tr>\n<td>unbind<\/td>\n<td>unmounted<\/td>\n<\/tr>\n<tr>\n<td>\u306a\u3057<\/td>\n<td>beforeUpdate<\/td>\n<\/tr>\n<tr>\n<td>\u306a\u3057<\/td>\n<td>beforeUnmount<\/td>\n<\/tr>\n<tr>\n<td>update<\/td>\n<td>\u306a\u3057<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\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=8355&amp;tmstv=1777536547\" rel=\"nofollow\" id=\"download-link-8355\" data-redirect=\"false\" >\n\tVue + datalist \u3067\u7c21\u5358\u306b\u5165\u529b\u5019\u88dc\u3092\u6709\u52b9\u306b\u3059\u308b<\/a>\n\n<p>\u203b <code>CDN<\/code>\u3092\u4f7f\u3063\u3066\u3044\u308b\u306e\u3067\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3066\u5c55\u958b\u3059\u308b\u3060\u3051\u3067\u5b9f\u884c\u3067\u304d\u307e\u3059\u3088\ud83d\ude0a<\/p>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f<code>Vue + datalist<\/code>\u3067\u30e6\u30fc\u30b6\u30d3\u30ea\u30c6\u30a3\u3092\u5411\u4e0a\u3055\u305b\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p><code>IE<\/code>\u3084\uff08\u53e4\u3044\uff09<code>edge<\/code>\u304c\u307b\u307c\u6d88\u6ec5\u3057\u3066\u304f\u308c\u305f\u306e\u3067\u3001\u3053\u3046\u3044\u3063\u305f<code>HTML 5<\/code>\u3084<code>CSS 3<\/code>\u306a\u3069\u306f\u7a4d\u6975\u7684\u306b\u4f7f\u3063\u3066\u3044\u304d\u305f\u3044\u3067\u3059\u306d\u3002\uff08\u3082\u3046\u4e00\u5ea6\u30b6\u30fc\u30c3\u3068\u30c1\u30a7\u30c3\u30af\u3057\u3068\u3053\u3046\u304b\u306a\u2753\uff09<\/p>\n<p>\u306a\u304a\u3001<code>datalist<\/code>\u306f\u5f53\u521d\u3059\u3063\u304b\u308a\u5fd8\u308c\u3066\u3044\u307e\u3057\u305f\u304c\u3001\u4fbf\u5229\u3067\u3059\u3057\u3001\u4f7f\u3044\u65b9\u3082\u7c21\u5358\u306a\u306e\u3067\u4eca\u5f8c\u5b9f\u969b\u306e\u958b\u767a\u3067\u3082\u4f7f\u3063\u3066\u3044\u3053\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u3001<code>datalist<\/code>\u306e\u30a2\u30a4\u30c7\u30a2\u3068\u3057\u3066\u306f\u300c<strong>\u76f4\u8fd1\u306b\u4fdd\u5b58\u3055\u308c\u305f\u6587\u5b57\u5217<\/strong>\u300d\u3092<code>GROUP BY<\/code>\u3067\u96c6\u8a08\u3057\u3001\u500b\u6570\u304c\u591a\u3044\u3082\u306e\u304b\u3089<code>datalist<\/code>\u306b\u30bb\u30c3\u30c8\u3059\u308c\u3070\u300c<strong>\u3088\u304f\u4f7f\u3046\u6587\u5b57\u5217\u30e9\u30f3\u30ad\u30f3\u30b0<\/strong>\u300d\u304c\u5165\u529b\u5019\u88dc\u306b\u306a\u3063\u3066\u4fbf\u5229\u304b\u306a\u3068\u8003\u3048\u3066\u307e\u3057\u305f\u3002<\/p>\n<p>\u305c\u3072\u7686\u3055\u3093\u3082\u8a66\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\u2757<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4445 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_2.png\" alt=\"\" width=\"370\" height=\"310\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_2.png 370w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_2-300x251.png 300w\" sizes=\"auto, (max-width: 370px) 100vw, 370px\" \/>\u300c\u308f\u304b\u308a\u3084\u3059\u3044\u8868\u73fe\u306e\u6280\u8853\u3001\u3068\u3044\u3046\u672c\u3092\u8aad\u3093\u3067\u307e\u3059\u3002<br \/>\n\u30e6\u30fc\u30b6\u30d3\u30ea\u30c6\u30a3\u306e\u52c9\u5f37\u306b\u306a\u308a\u307e\u3059\ud83d\udc4d\u300d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001Vue 3\u304c\u767b\u5834\u3057\u3066\u304b\u3089\u5c11\u3057\u6642\u9593\u304c\u7d4c\u3061\u307e\u3057\u305f\u3002\u57fa\u672c\u7684\u306b\u306f\u524d\u56de\u30d0\u30fc\u30b8\u30e7\u30f3\u3068\u540c\u3058\u69cb\u6210\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u79fb\u884c\u306f\u305d\u308c\u307b\u3069\u624b\u9593\u53d6\u308b\u3053\u3068\u306f\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u3002 \u203b \u305f &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=8347\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Vue + datalist \u3067\u7c21\u5358\u306b\u5165\u529b\u5019\u88dc\u3092\u6709\u52b9\u306b\u3059\u308b\uff08\u30c7\u30e2\u30da\u30fc\u30b8\u3042\u308a\uff09&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":8362,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,97],"tags":[],"class_list":["post-8347","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vue-js","category-97"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/8347","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=8347"}],"version-history":[{"count":7,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/8347\/revisions"}],"predecessor-version":[{"id":8361,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/8347\/revisions\/8361"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/8362"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8347"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}