{"id":1390,"date":"2020-01-08T15:22:42","date_gmt":"2020-01-08T06:22:42","guid":{"rendered":"https:\/\/took.jp\/?p=1390"},"modified":"2020-06-15T14:33:21","modified_gmt":"2020-06-15T05:33:21","slug":"post-1390","status":"publish","type":"post","link":"https:\/\/took.jp\/tech-blog\/post-1390\/","title":{"rendered":"Vuejs \u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u5185\u3067\u306eid\u91cd\u8907\u3092\u56de\u907f\u3059\u308b\u3010id\u3092\u632f\u308a\u306a\u304a\u3059\u3011"},"content":{"rendered":"<p>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u5185\u3067id\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u305f\u3081\u3001\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3067\u8907\u6570\u547c\u3073\u51fa\u3057\u305f\u3089\u3001id\u304c\u91cd\u8907\u3057\u3066\u3057\u307e\u3044\u3001\u8b66\u544a\u3055\u308c\u3066\u3057\u307e\u3044\u307e\u3057\u305f...\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306e\u4e2d\u8eab\u3092\u5f04\u308b\u3068\u3001\u5f71\u97ff\u7bc4\u56f2\u3082\u5e83\u304f\u3001\u9762\u5012\u306a\u305f\u3081\u3001id\u3092\u632f\u308a\u306a\u304a\u3059\u3088\u3046\u306b\u8a18\u8ff0\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u73fe\u72b6\u30b5\u30f3\u30d7\u30eb\uff08\u554f\u984c\u306e\u72b6\u614b\uff09<\/h2>\n<pre class=\"line-numbers\"><code class=\"language-javascript\">var mainTemplate = {\r\n    template: '#main-template',\r\n}\r\nvar vm = new Vue({\r\n    el: \"#app\",\r\n    components: {\r\n        'main-template': mainTemplate,\r\n    },\r\n});\r\n&lt;div id=\"app\"&gt;\r\n  &lt;main-template id=\"sample1\"&gt;\u30b5\u30f3\u30d7\u30eb1&lt;\/main-template&gt;\r\n  &lt;main-template id=\"sample2\"&gt;\u30b5\u30f3\u30d7\u30eb2&lt;\/main-template&gt;\r\n&lt;\/div&gt;\r\n&lt;script type=\"text\/x-template\" id=\"main-template\"&gt;\r\n  &lt;div id=\"test\"&gt;\r\n    &lt;slot&gt;&lt;\/slot&gt;\r\n  &lt;\/div&gt;\r\n&lt;\/script&gt;<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u3053\u306e\u307e\u307e\u3067\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30bf\u30b0\u304c\u751f\u6210\u3055\u308c\u3001\u300ctest\u300d\u3068\u3044\u3046ID\u304c\u91cd\u8907\u3057\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-javascript\">&lt;div id=\"sample\"&gt;\r\n  \u30b5\u30f3\u30d7\u30eb1\r\n&lt;\/div&gt;\r\n&lt;div id=\"sample\"&gt;\r\n  \u30b5\u30f3\u30d7\u30eb2\r\n&lt;\/div&gt;<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2>\u6539\u5584\u5f8c<\/h2>\n<pre class=\"line-numbers\"><code class=\"language-javascript\">var mainTemplate = {\r\n    template: '#main-template',\r\n}\r\nvar vm = new Vue({\r\n    el: \"#app\",\r\n    components: {\r\n        'main-template': mainTemplate,\r\n    },\r\n    mounted: function(){\r\n      var allTag = document.getElementById('sample2').getElementsByTagName('*');\r\n      for (var i = 0; allTag.length &gt; i; i++){\r\n        if(allTag[i].id != ''){\r\n          allTag[i].id += '2';\r\n        }\r\n      }\r\n    }\r\n});\r\n&lt;div id=\"app\"&gt;\r\n  &lt;main-template id=\"sample1\"&gt;\u30b5\u30f3\u30d7\u30eb1&lt;\/main-template&gt;\r\n  &lt;main-template id=\"sample2\"&gt;\u30b5\u30f3\u30d7\u30eb2&lt;\/main-template&gt;\r\n&lt;\/div&gt;\r\n&lt;script type=\"text\/x-template\" id=\"main-template\"&gt;\r\n  &lt;div id=\"test\"&gt;\r\n    &lt;slot&gt;&lt;\/slot&gt;\r\n  &lt;\/div&gt;\r\n&lt;\/script&gt;<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>mounted\u306e\u51e6\u7406\u3092\u8ffd\u52a0\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u3053\u308c\u306f\u3001\u30bf\u30b0\u751f\u6210\u524d\u306b\u5b9f\u884c\u3055\u308c\u308b\u51e6\u7406\u3067\u3059\u3002<\/p>\n<p>\u3053\u3053\u3067\u306f\u3001sample2\u3068\u3044\u3046id\u3092\u6e21\u3057\u305f\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u5185\u306b\u5b58\u5728\u3059\u308b\u3059\u3079\u3066\u306eID\u306e\u5f8c\u308d\u306b\u300c\uff12\u300d\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u3067ID\u304c\u88ab\u3089\u306a\u304f\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u305f\u3060\u3001\u3053\u306e\u3084\u308a\u65b9\u3060\u3068\u3001\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u5185\u306e\u30bf\u30b0\u3092\u3059\u3079\u3066\u53d6\u5f97\u3057\u3001for\u6587\u3067\u56de\u3057\u3001id\u3092\u66f8\u304d\u63db\u3048\u308b\u305f\u3081\u3001\u51e6\u7406\u304c\u91cd\u305f\u304f\u306a\u308a\u3001\u3042\u307e\u308a\u826f\u3044\u65b9\u6cd5\u3067\u306f\u306a\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u4ed6\u306b\u3001<\/p>\n<p><strong>\u30fbv-bind\u3092\u4f7f\u7528\u3057\u3001\u300c:id=\"'sample' + num\"\u300d\u306e\u3088\u3046\u306b\u3059\u308b<\/strong><\/p>\n<p><strong>\u30fbvue-uid\u30d7\u30e9\u30b0\u30a4\u30f3\u3092\u4f7f\u7528\u3059\u308b<\/strong><\/p>\n<p>\u3068\u3044\u3046\u65b9\u6cd5\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u524d\u8005\u306e\u5834\u5408\u3001\u66f8\u304d\u65b9\u304c\u60aa\u304b\u3063\u305f\u306e\u304b\u3046\u307e\u304f\u52d5\u4f5c\u304c\u3067\u304d\u306a\u304b\u3063\u305f\u3067\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u5185\u3067id\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u305f\u3081\u3001\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3067\u8907\u6570\u547c\u3073\u51fa\u3057\u305f\u3089\u3001id\u304c\u91cd\u8907\u3057\u3066\u3057\u307e\u3044\u3001\u8b66\u544a\u3055\u308c\u3066\u3057\u307e\u3044\u307e\u3057\u305f...\u3002 \u3057\u304b\u3057\u3001\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306e\u4e2d\u8eab\u3092\u5f04\u308b\u3068\u3001\u5f71\u97ff\u7bc4\u56f2\u3082\u5e83\u304f\u3001\u9762\u5012\u306a\u305f\u3081\u3001id\u3092\u632f\u308a\u306a\u304a\u3059\u3088\u3046\u306b\u8a18\u8ff0\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002 &#038;\u2026<\/p>\n","protected":false},"author":3,"featured_media":1836,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[62,66,65],"tags":[],"class_list":["post-1390","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-it","category-javascript","category-vuejs"],"_links":{"self":[{"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/posts\/1390","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/comments?post=1390"}],"version-history":[{"count":0,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/posts\/1390\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/media\/1836"}],"wp:attachment":[{"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/media?parent=1390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/categories?post=1390"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/tags?post=1390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}