{"id":7591,"date":"2017-02-21T05:35:35","date_gmt":"2017-02-20T20:35:35","guid":{"rendered":"http:\/\/www.webcyou.com\/?p=7591"},"modified":"2017-03-26T22:56:31","modified_gmt":"2017-03-26T13:56:31","slug":"vue-js-%e3%81%8c%e4%ba%88%e6%83%b3%e4%bb%a5%e4%b8%8a%e3%81%ab%e8%89%af%e3%81%8b%e3%81%a3%e3%81%9f%e3%81%ae%e3%81%a7%e3%80%81%e6%97%a2%e5%ad%98wordpress%e3%81%ab%e5%b0%8e%e5%85%a5%e3%80%82vue-js-vue-c","status":"publish","type":"post","link":"https:\/\/www.webcyou.com\/?p=7591","title":{"rendered":"Vue.js \u304c\u4e88\u60f3\u4ee5\u4e0a\u306b\u826f\u304b\u3063\u305f\u306e\u3067\u3001\u65e2\u5b58WordPress\u306b\u5c0e\u5165\u3002Vue.js (vue-class-component) + TypeScript + WordPress \u3067\u4f5c\u308b\u3001\u8a18\u4e8b\u8aad\u307f\u8fbc\u307f component \u300c\u74b0\u5883\u69cb\u7bc9\u7de8\u300d"},"content":{"rendered":"<p>\u3069\u3082\u3067\u3059\u3002<\/p>\n<p>\u30bf\u30a4\u30c8\u30eb\u9577\u3081\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u304b\u308c\u3053\u308c\u30016\u3001\uff17\u5e74\u653e\u7f6e\u6c17\u5473\u306eWordPress\u306e\u30b5\u30a4\u30c8\u3092 \u30b5\u30fc\u30d0\u30fc\u79fb\u8ee2\u306b\u4f34\u3044\u8272\u3005\u3068\u6574\u7406\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u65e2\u5b58\u306eWordPress\u306f\u3001\u304c\u3063\u3064\u308a\u30d7\u30e9\u30b0\u30a4\u30f3\u306b\u4f9d\u5b58\u3057\u3066\u3044\u308b\u3057jQuery\u30827\u5e74\u524d\u3050\u3089\u3044\u306b\u5165\u308c\u3063\u3071\u306a\u3057\u3002\u3002<\/p>\n<p>\u3068\u3044\u3046\u4e8b\u3067\u3001\u5916\u305b\u308b\u30d7\u30e9\u30b0\u30a4\u30f3\u306f\u5916\u3057\u3066\u3001\u3053\u308c\u3092\u6a5f\u306bjQuery\u3082\u5916\u305d\u3046\u3068\u3002<\/p>\n<p>\u3057\u305f\u3068\u3053\u308d\u3001\u3088\u304f\u3042\u308b\u300c<strong>\u3055\u3089\u306b\u8a18\u4e8b\u3092\u8aad\u307f\u8fbc\u3080<\/strong>\u300d\u30dc\u30bf\u30f3\u306e\u5b9f\u88c5\u304c\u3069\u3046\u3084\u3089\u5fc5\u8981\u3060\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-7674\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/8d56fd3618b003739bcc7f826fcedbb2.png\" alt=\"\" width=\"294\" height=\"79\" srcset=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/8d56fd3618b003739bcc7f826fcedbb2.png 978w, https:\/\/www.webcyou.com\/wp-content\/uploads\/8d56fd3618b003739bcc7f826fcedbb2-300x80.png 300w, https:\/\/www.webcyou.com\/wp-content\/uploads\/8d56fd3618b003739bcc7f826fcedbb2-768x206.png 768w, https:\/\/www.webcyou.com\/wp-content\/uploads\/8d56fd3618b003739bcc7f826fcedbb2-900x241.png 900w\" sizes=\"auto, (max-width: 294px) 100vw, 294px\" \/><\/p>\n<p>\u3053\u306e\u30dc\u30bf\u30f3\u3092\u62bc\u3059\u3068\u3001Ajax\u3067\u8a18\u4e8b\u3092\u53d6\u5f97\u3057\u3066\u304d\u3066\u3001\u8868\u793a\u3059\u308b\u3002\u3068\u8a00\u3063\u305f\u6a5f\u80fd\u3002<\/p>\n<p>\u4eca\u307e\u3067\u3001\u30d7\u30e9\u30b0\u30a4\u30f3\u3092\u5229\u7528\u3057\u3066\u304d\u305f\u306e\u3067\u3059\u304c\u3001\u5916\u305b\u308b\u306a\u3089\u5916\u3057\u3066\u81ea\u4f5c\u3057\u305f\u3044\u3067\u3059\u3088\u306d\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u305d\u3053\u3067\u3001\u3069\u3046\u305b\u306a\u3089\u65b0\u3057\u3081\u306e\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3092\u5165\u308c\u3061\u3083\u304a\u3046\u304b\u306a\u3068\u3001\u3069\u308c\u3092\u5165\u308c\u3088\u3046\u304b20\u79d2\u307b\u3069\u8003\u3048\u307e\u3057\u305f\u3002<\/p>\n<p>Angular2\u3092\u5165\u308c\u308b\u306b\u306f\u3061\u3087\u3063\u3068\u5927\u3052\u3055\u3059\u304e\u308b\u3057\u3001\u6c17\u8efd\u306a\u611f\u3058\u3067MVVM\u3057\u305f\u3044\u304b\u3089React\u306f\u3061\u3087\u3063\u3068\u9055\u3046\u304b\u306a\u3068\u3002<\/p>\n<p>\u3068\u3044\u3046\u4e8b\u3067\u6700\u8fd1\u3001\u8a71\u984c\u306e\u300c<strong>Vue JS<\/strong>\u300d\u306e\u51fa\u756a\u3067\u3059\u3088\uff01\uff01<\/p>\n<p>\u30d0\u30fc\u30b8\u30e7\u30f3\u304c2.0\u306b\u306a\u3063\u305f\u3068\u3044\u3046\u3053\u3068\u3067\u4f55\u3084\u3089\u3001\u8a55\u5224\u3082\u4e0a\u3005\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u304b\u306a\u308a\u306e\u4eba\u6c17\u3092\u535a\u3057\u3066\u304a\u308a\u307e\u3059\u306d\u3002<\/p>\n<p><strong>\u516c\u5f0f\u30da\u30fc\u30b8<\/strong><\/p>\n<p><a href=\"https:\/\/jp.vuejs.org\/\" target=\"_blank\">https:\/\/jp.vuejs.org\/<\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-7675\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/df4898cad1407447af88e935e6cfd0d4.png\" alt=\"\" width=\"441\" height=\"151\" srcset=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/df4898cad1407447af88e935e6cfd0d4.png 1502w, https:\/\/www.webcyou.com\/wp-content\/uploads\/df4898cad1407447af88e935e6cfd0d4-300x103.png 300w, https:\/\/www.webcyou.com\/wp-content\/uploads\/df4898cad1407447af88e935e6cfd0d4-768x263.png 768w, https:\/\/www.webcyou.com\/wp-content\/uploads\/df4898cad1407447af88e935e6cfd0d4-1024x350.png 1024w, https:\/\/www.webcyou.com\/wp-content\/uploads\/df4898cad1407447af88e935e6cfd0d4-900x308.png 900w\" sizes=\"auto, (max-width: 441px) 100vw, 441px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u306f\u516c\u5f0f\u30da\u30fc\u30b8\u3092\u53c2\u7167\u304f\u3060\u3055\u3044 \uff1e\uff1c<\/p>\n<p>&nbsp;<\/p>\n<p>\u3067\u3001\u4f7f\u3063\u3066\u884c\u304d\u305f\u3044\u306e\u3067\u3059\u304c\u3001\u3084\u306f\u308a<strong>TypeScript<\/strong>\u3067\u66f8\u3044\u3066\u3044\u304d\u305f\u3044\u3002\u3002\u3002<\/p>\n<p>\u304b\u308c\u3053\u308c\u30013\u5e74\u307b\u3069\u66f8\u3044\u3066\u304d\u307e\u3057\u305f\u304c\u3084\u306f\u308a\u578b\u304c\u3042\u308b\u306e\u306f\u826f\u3044\u3067\u3059\u3088\u306d\u3002<\/p>\n<p>\u578b\u304c\u5fc5\u8981\u3068\u3044\u3046\u3053\u3068\u3082\u5f90\u3005\u306b\u6d78\u900f\u3057\u3060\u3057\u3066\u304a\u308a\u307e\u3059\u306d\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001<strong>TypeScript\u3092\u4f7f\u3046\u306a\u3089\u3053\u308c\u3092\u4f7f\u3048\u3068\u3001\u516c\u5f0f\u3082\u63a8\u5968<\/strong>\u3057\u3066\u3044\u308b<\/p>\n<p>\u300c<strong>vue-class-component<\/strong>\u300d\u3092\u4f7f\u3046\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p><strong>github<\/strong><\/p>\n<p><a href=\"https:\/\/github.com\/vuejs\/vue-class-component\" target=\"_blank\">https:\/\/github.com\/vuejs\/vue-class-component<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>\u30b5\u30f3\u30d7\u30eb\u3092\u898b\u3066\u308f\u304b\u308b\u3088\u3046\u306b\u3001Compornent \u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u3001Angular Like\u306b\u8a18\u8ff0\u3057\u3066\u3044\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\uff08\u306a\u3093\u3068\u306a\u304f\u66f8\u3044\u3066\u3044\u3066\u3001\u7d50\u679c Angular\u307f\u305f\u304f\u306a\u3063\u3066\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u304cw<\/p>\n<p>&nbsp;<\/p>\n<p>\u30d3\u30eb\u30c9\u74b0\u5883\u306f\u3053\u3093\u306a\u611f\u3058<\/p>\n<p><strong>Dependencies<\/strong><br \/>\n\u30fb Vue.js<\/p>\n<p>\u30fb vue-class-component<\/p>\n<p><strong>Dev Dependencies<\/strong><br \/>\n\u30fb TypeScript<br \/>\n\u30fb Webpack<br \/>\n\u30fb ts-loader<br \/>\n\u30fb html-loader<\/p>\n<p>\u3067\u306f\u3001\u65e9\u901f\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/p>\n<h4>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h4>\n<p><strong>npm install<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">$ npm install vue\r\n$ npm install vue-class-component\r\n$ npm install html-loader\r\n$ npm install ts-loader<\/pre>\n<p>TypeScript\u306a\u306e\u3067\u3001Typings\u3067\u578b\u5b9a\u7fa9\u30d5\u30a1\u30a4\u30eb\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u305f\u3044\u306e\u3067\u3059\u304c\u3001\u5b09\u3057\u3044\u3053\u3068\u306bVue\u306fTypeScript\u306b\u3082\u5bfe\u5fdc\u3057\u3066\u3044\u3066\u7279\u306b\u5225\u9014\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u5fc5\u8981\u3082\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u305d\u308c\u3067\u306f\u3001webpack\u306econfig\u3092\u4f5c\u6210\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<h4>webpack<\/h4>\n<p><strong>webpack.config.js<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\"use strict\";\r\nvar webpack = require('webpack');\r\n\r\nmodule.exports = {\r\n  entry: \".\/ts\/index.ts\",\r\n  output: {\r\n    filename: \"bundle.js\",\r\n    path: \".\/js\"\r\n  },\r\n  module: {\r\n    loaders: &#x5B;\r\n      { test: \/\\.tsx?$\/, loader: \"ts-loader\" },\r\n      { test: \/\\.html$\/, loader: \"html-loader?minimize=false\" }\r\n    ]\r\n  },\r\n  resolve: {\r\n    extensions: &#x5B;\"\", \".ts\", \".tsx\", \".js\"],\r\n    alias: {\r\n      'vue$': 'vue\/dist\/vue.common.js'\r\n    }\r\n  },\r\n  plugins: &#x5B;\r\n    new webpack.DefinePlugin({\r\n      'process.env': {\r\n        NODE_ENV: '\"production\"'\r\n      }\r\n    }),\r\n    new webpack.optimize.UglifyJsPlugin({\r\n      compress: {\r\n        warnings: false\r\n      }\r\n    })\r\n  ]\r\n};<\/pre>\n<p>\u306a\u3093\u3068\u3082\u306a\u3044\u3001\u307b\u307cwebpack\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u8a2d\u5b9a\u306a\u306e\u3067\u3059\u304c\u3001\u6c17\u3092\u3064\u3051\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u6240\u3068\u3057\u3066\u3001<\/p>\n<p>resolve \u306e aliias\u3068\u3057\u3066\u300cvue$ : vue\/dist\/vue.common.js\u300d\u3092\u5b9a\u7fa9\u3057\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u3068\u3053\u308d\u3067\u3059\u306d\u3002 \uff1e\uff1c<\/p>\n<p>\u3053\u308c\u304c\u306a\u3044\u3068\u30b3\u30f3\u30d1\u30a4\u30eb\u304c\u901a\u3089\u305a\u3001\u5c11\u3005\u82e6\u52b4\u3057\u307e\u3057\u305f orz<\/p>\n<p>\u4f59\u308a\u3001\u65e5\u672c\u8a9e\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3082\u306a\u3044\u3068\u3044\u3046\u3002\u3002<\/p>\n<p><strong>package.json<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\"scripts\": {\r\n    \"webpack\": \"webpack\",\r\n    \"webpack:w\": \"webpack --progress --colors --watch\"\r\n  },<\/pre>\n<p>\u306a\u308b\u3079\u304f\u6700\u5c0f\u9650\u3067\u884c\u304d\u305f\u3044\u306e\u3067\u3001 npm scripts\u3067webpack\u3092\u5b9f\u884c\u3067\u304d\u308b\u3088\u3046\u306b\u3068\u3002<\/p>\n<h4>ts\u30d5\u30a1\u30a4\u30eb\u4f5c\u6210<\/h4>\n<p>\u30a8\u30f3\u30c8\u30ea\u30fc\u30dd\u30a4\u30f3\u30c8\u3092index.ts \u3068\u3057\u307e\u3057\u305f\u306e\u3067\u3001index.ts\u3092\u4f5c\u6210\u3002<\/p>\n<p>\u3068\u305d\u306e\u524d\u306b\u3056\u3063\u3068\u3001\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u69cb\u6210\u3092<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">ts\/\r\n\u251c\u2500\u2500components\/\r\n\u251c\u2500\u2500service\/\r\n\u251c\u2500\u2500store\/\r\n\u251c\u2500\u2500bus.ts\r\n\u251c\u2500\u2500components.ts\r\n\u2514\u2500\u2500index.ts<\/pre>\n<p>\u30b7\u30f3\u30d7\u30eb\u306b\u3053\u306e\u3088\u3046\u306a\u611f\u3058\u3068\u306a\u308a\u307e\u3057\u305f\u3002\u306a\u3093\u3068\u306a\u304fAngular\u5bc4\u308a\u306a\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u69cb\u9020\u3002<\/p>\n<p>\u3067\u306f\u3001\u4e00\u5fdc\u8aac\u660e\u3092\u3002<\/p>\n<p>\u300c<strong>components<\/strong>\u300d\u306f\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306ets\u3068\u305d\u308c\u306b\u5bfe\u3068\u306a\u308bhtml\u304c\u683c\u7d0d\u3055\u308c\u308b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3067\u3059\u3002<\/p>\n<p>\u300c<strong>service<\/strong>\u300d\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306f\u3001\u53e4\u6765Angular\u7b49\u306e\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u3067\u3082\u305d\u3046\u3067\u3059\u304c\u3001Ajax\u7b49\u306b\u3088\u308b\u901a\u4fe1\u5468\u308a\u306e\u51e6\u7406\u3092\u683c\u7d0d\u3059\u308b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3067\u3059\u3002<\/p>\n<p>\u300c<strong>store<\/strong>\u300d\u306f\u3001Flux\u7b49\u3068\u306f\u3061\u3087\u3063\u3068\u7570\u306a\u308a\u30e2\u30c7\u30eb\u5c64\u3092\u683c\u7d0d\u3059\u308b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3067\u3059\u3002<\/p>\n<p>\u300c<strong>bus.ts<\/strong>\u300d\u306f\u3001\u516c\u5f0f\u3067\u3082\u66f8\u304b\u308c\u3066\u3044\u308b\u3088\u3046\u306bpubsub\u306e\u8cac\u52d9\u3092\u6301\u3064\u30d5\u30a1\u30a4\u30eb\u3068\u306a\u308a\u307e\u3059\u3002\uff08\u8ffd\u3063\u3066\u8a73\u7d30\u3092\uff09<\/p>\n<p>\u300c<strong>components.ts<\/strong>\u300d\u306f\u3001\u5404components\u3092\u96c6\u7d04\u3055\u305b\u308b\u30d5\u30a1\u30a4\u30eb\u3002<\/p>\n<p>\u300c<strong>index.ts<\/strong>\u300d\u306f\u30a8\u30f3\u30c8\u30ea\u30fc\u30dd\u30a4\u30f3\u30c8\u3068\u306a\u308b\u30d5\u30a1\u30a4\u30eb\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u3067\u306f\u3001index.ts\u3092\u4f5c\u6210\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p><strong>index.ts<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\"use strict\";\r\nimport Vue = require('vue');\r\n\r\nimport {\r\n  PostMoreBtn,\r\n  PostList\r\n} from '.\/components';\r\n\r\nconst app = new Vue({\r\n  el: '#app',\r\n  components: {\r\n    PostMoreBtn,\r\n    PostList\r\n  }\r\n});<\/pre>\n<p>\u4eca\u56de\u306f\u3001\u300c<strong>\u3055\u3089\u306b\u8a18\u4e8b\u3092\u8aad\u307f\u8fbc\u3080<\/strong>\u300d\u30dc\u30bf\u30f3\u306e\u5b9f\u88c5\u3092\u884c\u3044\u305f\u3044\u306e\u3067\u3001components\u306f\u300c<strong>PostMoreBtn<\/strong>\u300d\u3068\u300c<strong>PostList<\/strong>\u300d\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>Vue\u3092require\u3057\u3066\u3001\u5404components\u3092import\u3002<\/p>\n<p>Vue\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306bcomponents\u3092\u5b9a\u7fa9\u3057\u3001\u4f5c\u6210\u3002\u5909\u6570app\u306b\u4ee3\u5165\u3002<\/p>\n<p><strong>components.ts<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">export * from  '.\/components\/post-more-btn';\r\nexport * from  '.\/components\/post-list';<\/pre>\n<p>components\u30d5\u30a1\u30a4\u30eb\u5074\u306f\u3053\u3093\u306a\u611f\u3058\u3067\u3059\u306d\u3002<\/p>\n<p>components\u4f5c\u6210\u3068\u5171\u306b\u8ffd\u52a0\u3057\u3066\u3044\u304f\u611f\u3058\u3067\u3059\u306d\u3002<\/p>\n<p>\u307e\u3002\u3053\u306e\u8fba\u3001Angular\u3092\u3084\u3063\u3066\u3044\u308b\u65b9\u3060\u3068\u3001\u7279\u306b\u5909\u308f\u308a\u306a\u3044\u611f\u3058\u3067\u3059\u304b\u306d\u3002<\/p>\n<p>store\u306e\u65b9\u3082\u4f5c\u6210\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><strong>store\/post.ts<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">interface Category {\r\n  readonly name: string;\r\n  readonly url: string;\r\n}\r\n\r\ninterface Tag {\r\n  readonly name: string;\r\n  readonly url: string;\r\n}\r\n\r\nexport default class Post {\r\n  public title: string;\r\n  public date: string;\r\n  public imageUrl: string;\r\n  public postDetail: string;\r\n  public categoryList: Category&#x5B;];\r\n  public tagList: Tag&#x5B;];\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>WordPress\u306e\u8a18\u4e8b\u3092\u30e2\u30c7\u30eb\u3068\u3057\u3066\u6271\u3044\u305f\u3044\u306e\u3067\u3001\u4e0a\u8a18\u306e\u3088\u3046\u306a\u611f\u3058\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\uff08TypeScript\u306e\u8a73\u7d30\u7b49\u306f\u5272\u611b\u3055\u305b\u3066\u3044\u305f\u3060\u304d\u307e\u3059\u3002<\/p>\n<p>Service\u5c64\u3067WordPress\u5074\u306eAPI\u3068\u3001Ajax\u901a\u4fe1\u3057\u3066\u578b\u4ed8\u3051\u3057\u3066\u3044\u304f\u30a4\u30e1\u30fc\u30b8\u3067\u3059\u306d\u3002<\/p>\n<p>\u305d\u308c\u3067\u306f\u3001components\u306e\u4f5c\u6210\u3092\u3002<\/p>\n<p><strong>components\/post-list.ts<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">import Vue = require('vue');\r\nimport Component from 'vue-class-component';\r\nimport bus from '..\/bus'\r\nimport Post from '..\/store\/post';\r\n\r\n@Component({\r\n  template: require('.\/post-list.html')\r\n})\r\nexport class PostList extends Vue {\r\n  private posts: Post&#x5B;];\r\n\r\n  data(): any {\r\n    return {\r\n      posts: &#x5B;]\r\n    }\r\n  }\r\n\r\n  created() {\r\n    bus.$on('update-post', this.onUpdatePost)\r\n  }\r\n\r\n  destroyed() {\r\n    bus.$off('update-post', this.onUpdatePost)\r\n  }\r\n\r\n  onUpdatePost(posts: any): void {\r\n    posts.forEach((post: any) =&gt; {\r\n      this.posts.push(post);\r\n    });\r\n  }\r\n\r\n}<\/pre>\n<p>\u3053\u3053\u3067\u3001vue-class-component\u3092\u5229\u7528\u3059\u308b\u306e\u3067\u3001vue-class-component\u3092import\u3057\u3066\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001html-loader\u3092\u5229\u7528\u3059\u308b\u3068\u3001component\u3092html\u3068\u3057\u3066\u8aad\u307f\u8fbc\u307f\u4f7f\u7528\u3067\u304d\u307e\u3059\u306e\u3067\u3001\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306f\u5225\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>bus\u306b\u95a2\u3057\u3066\u306f\u3001\u6b21\u56de\u8ffd\u3063\u3066\u8a73\u7d30\u3092\uff1e\uff1c<\/p>\n<p>\u306a\u306e\u3067\u3001\u300c<strong>created<\/strong>\u300d\u3001\u300c<strong>destroyed<\/strong>\u300d\u95a2\u6570\u306f\u98db\u3070\u3057\u3066\u3001\u300c<strong>onUpdatePost<\/strong>\u300d\u95a2\u6570\u3092\u3002<\/p>\n<p>\u3068\u3044\u3063\u3066\u3082\u8aac\u660e\u3059\u308b\u307b\u3069\u3067\u3082\u306a\u3044\u306e\u3067\u3059\u304c\u3001Ajax\u901a\u4fe1\u3057\u305f\u3042\u3068\u3001onUpdatePost\u95a2\u6570\u3092\u7d4c\u3066post\u3092\u4fdd\u6301\u3057\u307e\u3059\u3002<\/p>\n<p><strong>components\/post-list.html<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;div&gt;\r\n  &lt;div class=&quot;post section&quot; v-for=&quot;post in posts&quot;&gt;\r\n    &lt;h2 class=&quot;post-title&quot;&gt;&lt;a :href=&quot;post.postUrl&quot;&gt;{{ post.title }}&lt;\/a&gt;&lt;\/h2&gt;\r\n    &lt;ul&gt;\r\n      &lt;li v-for=&quot;category in post.categoryList&quot;&gt;&lt;a :href=&quot;category.url&quot; rel=&quot;category&quot;&gt;{{ category.name }}&lt;\/a&gt;&lt;\/li&gt;&lt;\/ul&gt;\r\n    &lt;p&gt;{{ post.date }}&lt;\/p&gt;\r\n    &lt;p&gt;&lt;img :src=&quot;post.imageUrl&quot; :alt=&quot;post.title&quot;&gt;&lt;\/p&gt;\r\n    &lt;p&gt;{{ post.postDetail }}&lt;\/p&gt;\r\n    &lt;p&gt;&lt;a :href=&quot;post.postUrl&quot;&gt;&lt;b class=&quot;icon next&quot;&gt;&lt;\/b&gt;\u7d9a\u304d\u3092\u8aad\u3080&lt;\/a&gt;&lt;\/p&gt;\r\n    &lt;div class=&quot;postTag&quot;&gt;\r\n    &lt;p&gt;&lt;a :href=&quot;tag.url&quot; rel=&quot;tag&quot;&gt;{{ tag.name }}&lt;\/a&gt;&lt;span v-if=&quot;post.tagList.length &gt; (index + 1)&quot;&gt;,&lt;\/span&gt;&lt;\/p&gt;\r\n  &lt;\/div&gt;\r\n&lt;\/div&gt;<\/pre>\n<p>WordPress\u306e\u8a18\u4e8b\u306e\u30ea\u30b9\u30c8\u3068\u306a\u308b\u90e8\u5206\u3067\u3059\u3002<\/p>\n<p>\u3056\u3063\u3068\u3001\u3053\u3093\u306a\u611f\u3058\u3067\u3057\u3087\u3046\u304b\u3002\u3002\u3053\u306e\u8fba\u306f\u4efb\u610f\u3067\u3002vueJS\u306e\u30d0\u30a4\u30f3\u30c9\u306e\u8a18\u8ff0\u306a\u3069\u306f\u5272\u611b\u3055\u305b\u3066\u3044\u305f\u3060\u304d\u307e\u3059\u3002<\/p>\n<p>\u3061\u3087\u3063\u3068\u6c17\u3092\u3064\u3051\u308b\u70b9\u3068\u3057\u3066\u3001\u30d5\u30a1\u30a4\u30eb\u306e\u6700\u521d\u306bvueJS\u306e\u30d0\u30a4\u30f3\u30c9\u3092\u8a18\u8ff0\u3057\u3066\u3044\u308b\u3068\u3046\u307e\u304f\u884c\u304b\u305a\u3001\u7a7adiv\u3092\u56f2\u3046\u3053\u3068\u3067\u907f\u3051\u307e\u3057\u305f\u3002\u3002<br \/>\n\uff08\u3053\u306e\u8fba\u3001\u3069\u3046\u306b\u304b\u306a\u3089\u306a\u3044\u306e\u304b\u3002\u3002\uff09<\/p>\n<p>\u305d\u308c\u3067\u306f\u3001\u300c<strong>\u3055\u3089\u306b\u8a18\u4e8b\u3092\u8aad\u307f\u8fbc\u3080<\/strong>\u300d\u30dc\u30bf\u30f3\u306e\u7b87\u6240\u3092\u5b9f\u88c5\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><strong>components\/post-more-btn.ts<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">import Vue = require('vue');\r\nimport Component from 'vue-class-component';\r\nimport PostMoreService from '..\/service\/post-more.service';\r\nimport bus from '..\/bus'\r\n\r\n@Component({\r\n  props: &#x5B;'nowPostNum'],\r\n  template: require('.\/post-more-btn.html')\r\n})\r\nexport class PostMoreBtn extends Vue {\r\n  private nowPostNum: number;\r\n  private postMoreService: PostMoreService = new PostMoreService();\r\n\r\n  onClick (): void {\r\n    this.postMoreService.fetchData(this.nowPostNum)\r\n      .then((response: any) =&gt; {\r\n        bus.$emit('update-post', response.data);\r\n\r\n        this.nowPostNum += 10;\r\n      }, (error: any) =&gt; {\r\n        console.log(error);\r\n      });\r\n  }\r\n}<\/pre>\n<p>\u3053\u306e\u30dc\u30bf\u30f3\u3092\u62bc\u3059\u3068\u3001<strong>\u975e\u540c\u671f\u3067WordPress\u5074\u306eAPI\u3068\u3001Ajax\u901a\u4fe1<\/strong>\u3057\u305f\u3044\u306e\u3067\u3001<strong>PostMoreService\u306e\u30b5\u30fc\u30d3\u30b9\u5c64\u3092\u8aad\u307f\u8fbc\u3093\u3067<\/strong>\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>props [&#8216;nowPostNum&#8217;] \u3067\u3001\u5916\u304b\u3089\u8a18\u4e8b\u3092\u4eca\u4f55\u4ef6\u8868\u793a\u3057\u3066\u3044\u308b\u304b\u3092\u53d7\u3051\u53d6\u308a\u307e\u3059\u3002<\/p>\n<p>postMoreService\u3067\u8a18\u4e8b\u30c7\u30fc\u30bf\u3092fetch\u3067\u304d\u305f\u3089\u3001bus\u306b\u901a\u77e5\u3059\u308b\u305f\u3081 <strong>bus.$emit update-post<\/strong>\u3092\u884c\u3044\u3001\u73fe\u5728\u306e\u8a18\u4e8b\u8868\u793a\u300cnowPostNum\u300d\u3092\u52a0\u7b97\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p><strong>components\/post-more-btn.html<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;div class=&quot;moreBtnBox&quot;&gt;\r\n  &lt;a @click=&quot;onClick&quot;&gt;\u4ed6\u306e\u8a18\u4e8b\u3092\u8aad\u307f\u8fbc\u3080&lt;\/a&gt;\r\n&lt;\/div&gt;<\/pre>\n<p>\u30dc\u30bf\u30f3\u5074\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3068\u306a\u308a\u307e\u3059\u3002<br \/>\n\u3053\u3061\u3089\u306f\u30b7\u30f3\u30d7\u30eb\u3067\u3001\u30af\u30ea\u30c3\u30af\u3055\u308c\u305f\u3089\u5148\u7a0b\u306eonClick\u95a2\u6570\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<p>\u3068\u3001\u4e00\u65e6\u306f\u3053\u3053\u307e\u3067\u3067\u3001<\/p>\n<p>\uff08\u3053\u306e\u8fba\u3067\u3082\u3046\u3001Angular\u307d\u304f\u306a\u3063\u3066\u6765\u3066\u308b\u306e\u304c\u3001\u308f\u304b\u308b\u304b\u3068w<\/p>\n<p>\u610f\u5916\u306b\u9577\u304f\u306a\u308a\u305d\u3046\u306a\u306e\u3067\u3001\u6b21\u56de\u306f<strong> WordPress\u306eAPI\u3068\u9023\u643a\u3057\u3066\u3001PostMoreService\u3067\u53d7\u53d6\u308a \u8a18\u4e8b\u3092\u66f4\u65b0<\/strong>\u3057\u3066\u3044\u304f\u7b87\u6240\u3092\u66f8\u3044\u3066\u3044\u3051\u308c\u3070\u3068\u601d\u3044\u307e\u3059\u30fc<\/p>\n<p>\u3067\u306f\u3067\u306f\u3002<\/p>\n<p><strong>\u7d9a\u304d<\/strong><br \/>\n<a href=\"https:\/\/www.webcyou.com\/?p=7711\">Vue.js \u304c\u4e88\u60f3\u4ee5\u4e0a\u306b\u826f\u304b\u3063\u305f\u306e\u3067\u3001\u65e2\u5b58WordPress\u306b\u5c0e\u5165\u3002Vue.js (vue-class-component) + TypeScript + WordPress \u3067\u4f5c\u308b\u3001\u8a18\u4e8b\u8aad\u307f\u8fbc\u307f component \u300c\u5b9f\u88c5\u7de8\u300d<\/a><br \/>\n&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-7676\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/f91bf60971cc8e5761d6dc4db12368cb.png\" alt=\"\" width=\"686\" height=\"369\" srcset=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/f91bf60971cc8e5761d6dc4db12368cb.png 1914w, https:\/\/www.webcyou.com\/wp-content\/uploads\/f91bf60971cc8e5761d6dc4db12368cb-300x161.png 300w, https:\/\/www.webcyou.com\/wp-content\/uploads\/f91bf60971cc8e5761d6dc4db12368cb-768x413.png 768w, https:\/\/www.webcyou.com\/wp-content\/uploads\/f91bf60971cc8e5761d6dc4db12368cb-1024x551.png 1024w, https:\/\/www.webcyou.com\/wp-content\/uploads\/f91bf60971cc8e5761d6dc4db12368cb-900x484.png 900w\" sizes=\"auto, (max-width: 686px) 100vw, 686px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3069\u3082\u3067\u3059\u3002 \u30bf\u30a4\u30c8\u30eb\u9577\u3081\u306b\u306a\u308a\u307e\u3057\u305f\u3002 \u304b\u308c\u3053\u308c\u30016\u3001\uff17\u5e74\u653e\u7f6e\u6c17\u5473\u306eWordPress\u306e\u30b5\u30a4\u30c8\u3092 \u30b5\u30fc\u30d0\u30fc\u79fb\u8ee2\u306b\u4f34\u3044\u8272\u3005\u3068\u6574\u7406\u3057\u3066\u3044\u307e\u3059\u3002 \u65e2\u5b58\u306eWordPress\u306f\u3001\u304c\u3063\u3064\u308a\u30d7\u30e9\u30b0\u30a4\u30f3\u306b\u4f9d\u5b58\u3057\u3066\u3044\u308b\u3057jQuery\u30827\u5e74 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[177,168,176,40,166,37,47,180,173,44,45,111,39,178,138,78,114,118,205,206],"class_list":{"0":"post-7591","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-javascript","7":"tag-css3","8":"tag-html","9":"tag-html5","10":"tag-ios-sdk","11":"tag-iphone","12":"tag-iphone-","13":"tag-javascript-2","14":"tag-mysql","15":"tag-php","16":"tag-web","18":"tag-wordpress-2","19":"tag-39","20":"tag-178","21":"tag-138","22":"tag-78","23":"tag-114","24":"tag-118","25":"tag-205","26":"tag-206"},"_links":{"self":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/7591","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7591"}],"version-history":[{"count":14,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/7591\/revisions"}],"predecessor-version":[{"id":7733,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/7591\/revisions\/7733"}],"wp:attachment":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}