{"id":386,"date":"2019-05-31T10:00:29","date_gmt":"2019-05-31T01:00:29","guid":{"rendered":"http:\/\/localhost:8000\/?p=386"},"modified":"2021-01-23T12:32:07","modified_gmt":"2021-01-23T03:32:07","slug":"vue-typescript","status":"publish","type":"post","link":"http:\/\/localhost:8000\/2019\/05\/vue-typescript.html","title":{"rendered":"Vue.js+TypeScript\u3067\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u30a2\u30d7\u30ea\u3092\u69cb\u7bc9\u6642\u306eTips"},"content":{"rendered":"
\u73fe\u5728\u30d7\u30e9\u30a4\u30d9\u30fc\u30c8\u3067\u4f5c\u3063\u3066\u3044\u308bWEB\u30b5\u30fc\u30d3\u30b9\u306e\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u3092\u4f5c\u308b\u306b\u3042\u305f\u3063\u3066\u3001Vue.js\uff0bTypeScript\u3092\u8a66\u3057\u3066\u307f\u308b\u3053\u3068\u306b\u3057\u305f\u3002 \u30e1\u30e2\u3092\u7de8\u96c6\u3059\u308b\u753b\u9762\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n \u4ee5\u524d\u8a18\u4e8b\u3092\u66f8\u3044\u305f\u306e\u3067\u3053\u3061\u3089\u3092\u53c2\u7167\u306e\u3053\u3068\u3002 \u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u5bfe\u8a71\u578b\u3067\u4f5c\u6210\u3059\u308b\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u5185\u5bb9\u3092\u6c7a\u3081\u3066\u3044\u304f\u3002<\/p>\n \u4ee5\u4e0b\u306e\u8a2d\u5b9a\u3067\u4f5c\u6210\u3057\u305f\u3002<\/p>\n \u30b5\u30fc\u30d0\u3092\u8d77\u52d5\u3059\u308b\u3002<\/p>\n \u30b5\u30a4\u30c8\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u3001\u3068\u308a\u3042\u3048\u305a\u30b5\u30f3\u30d7\u30eb\u753b\u9762\u304c\u8868\u793a\u3055\u308c\u308b\u3002 \u7570\u306a\u308b\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u30c4\u30fc\u30eb\u306b\u304a\u3044\u3066\u3001\u30bf\u30fc\u30b2\u30c3\u30c8\u30d6\u30e9\u30a6\u30b6\u3084Node.js\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u30b7\u30a7\u30a2\u3059\u308b\u305f\u3081\u306e\u8a2d\u5b9a\u3092\u8a18\u8f09\u3059\u308b\u3082\u306e\u3002 EditorConfig\u306f\u7570\u306a\u308b\u30a8\u30c7\u30a3\u30bf\u3084IDE\u3067\u4e00\u8cab\u3057\u305f\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u30b9\u30bf\u30a4\u30eb\u3092\u7dad\u6301\u3059\u308b\u305f\u3081\u306e\u8a2d\u5b9a\u3092\u8a18\u8f09\u3059\u308b\u3082\u306e\u3002 \u4e0b\u8a18\u8a2d\u5b9a\u306f\u3001\u7279\u5b9a\u306e\u62e1\u5f35\u5b50\u306b\u304a\u3044\u3066\u3001\u30a4\u30f3\u30c7\u30f3\u30c8\u306e\u30b9\u30bf\u30a4\u30eb\u3084\u884c\u672b\u306e\u30b9\u30da\u30fc\u30b9\u3001\u6700\u7d42\u884c\u306e\u6539\u884c\u306a\u3069\u306e\u6271\u3044\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u308b\u3002 EsLint\u306f\u3001JavaScript\u3092\u5b9f\u884c\u305b\u305a\u306b\u9759\u7684\u306bJavaScript\u30b3\u30fc\u30c9\u306e\u554f\u984c\u3092\u767a\u898b\u3059\u308b\u305f\u3081\u30c4\u30fc\u30eb\u3002 \u4e0b\u8a18\u8a2d\u5b9a\u306e\u610f\u5473\u306f\u30b3\u30fc\u30c9\u4e0a\u306b\u30b3\u30e1\u30f3\u30c8\u3067\u8a18\u8f09\u3002\u8a73\u7d30\u306f\u3053\u3061\u3089<\/a>\u3092\u53c2\u7167\u306e\u3053\u3068\u3002<\/p>\n git\u7ba1\u7406\u5bfe\u8c61\u5916\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u6307\u5b9a\u3057\u3066\u304f\u308c\u3066\u3044\u308b\u3002<\/p>\n Babel\u306fJavaScript\u306e\u30b3\u30f3\u30d1\u30a4\u30e9\u3002\u53e4\u3044\u30d6\u30e9\u30a6\u30b6\u3067ES2015\u4ee5\u964d\u306e\u65b0\u3057\u3044\u30d0\u30fc\u30b8\u30e7\u30f3\u306eJavaScript\u3092\u52d5\u304b\u305b\u308b\u3088\u3046\u3001\u5f8c\u65b9\u4e92\u63db\u6027\u306e\u3042\u308b\u30d0\u30fc\u30b8\u30e7\u30f3\u306eJavaScript\u3078\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u3066\u304f\u308c\u308b\u3002 npm\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u5bfe\u8c61\u306eJavaScript\u30d1\u30c3\u30b1\u30fc\u30b8\u3068\u30bf\u30b9\u30af\u306e\u8a2d\u5b9a\u3002 PostCSS\u306fJS\u30d7\u30e9\u30b0\u30a4\u30f3\u3067\u30b9\u30bf\u30a4\u30eb\u3092\u5909\u63db\u3059\u308b\u305f\u3081\u306e\u30c4\u30fc\u30eb\u3002\u5909\u6570\u306fmixin\u3092\u30b5\u30dd\u30fc\u30c8\u3057\u3066\u304a\u308a\u3001\u5c06\u6765\u306eCSS\u30b7\u30f3\u30bf\u30c3\u30af\u30b9\u3067css\u3092\u8a18\u8ff0\u3067\u304d\u308b\u3089\u3057\u3044\u3002 TypeScript\u306b\u95a2\u3059\u308b\u8a2d\u5b9a\u3002\u8a73\u7d30\u306f\u3053\u3061\u3089<\/a>\u3092\u53c2\u7167\u306e\u3053\u3068\u3002<\/p>\n \u3084\u308a\u305f\u3044\u3053\u3068\u5225\u306bTips\u3092\u8ffd\u8a18\u3057\u3066\u3044\u304f\u65b9\u5f0f\u306b\u3057\u3088\u3046\u3068\u601d\u3046\u3002<\/p>\n \u3053\u3061\u3089<\/a>\u3092\u53c2\u8003\u306b\u3001 \u3053\u308c\u306b\u3088\u308a\u3001Vue\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304b\u3089\u3044\u3064\u3067\u3082option\u306e\u5024\u3092\u53d6\u5f97\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u3002<\/p>\n \u4eca\u56de\u306f\u3001Login\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3067\u30ed\u30b0\u30a4\u30f3\u304c\u5b8c\u4e86\u3057\u305f\u3089\u3001\u89aa\u306eApp\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e \u307e\u305a\u306f\u3001\u5b50\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e \u6b21\u306b\u3001\u89aa\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e axios<\/a>\u3092\u4f7f\u3063\u3066API\u3092\u547c\u3073\u51fa\u3059\u3002 \u307e\u305a\u306f\u3001\u4f9d\u5b58\u95a2\u4fc2\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n \u4eca\u56de\u306f\u3001 \uff11. \u30d7\u30ed\u30d1\u30c6\u30a3\u304c \uff12. \u30d7\u30ed\u30d1\u30c6\u30a3\u304c \uff13. \u30d7\u30ed\u30d1\u30c6\u30a3\u304c \u4eca\u56de\u306f\u3001\u30d7\u30ed\u30d1\u30c6\u30a3\u304c \u4eca\u56de\u306fvue-cli\u3092\u4f7f\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u3053\u3061\u3089<\/a>\u3092\u53c2\u8003\u306b\u3057\u305f\u3002 <\/p>\n \u4ee5\u4e0b\u306e\u8a18\u8ff0\u304c\u307b\u307c\u5168\u3066\u3092\u8868\u3057\u3066\u3044\u308b\u3068\u601d\u3046\u3002<\/p>\n .env # loaded in all cases \u4eca\u56de\u306f\u3001 API\u306e\u30d9\u30fc\u30b9URL\u306f\u3001 Google OAuth\u8a8d\u8a3c\u306e\u30af\u30e9\u30a4\u30a2\u30f3\u30c8ID\u306f\u3001\u30bb\u30f3\u30b7\u30c6\u30a3\u30d6\u306a\u60c5\u5831\u306a\u306e\u3067GIT\u306bcommit\u3057\u305f\u304f\u306a\u3044\u3002\u305d\u306e\u305f\u3081\u3001 \u3042\u3068\u306f\u3001 \u73fe\u5728\u30d7\u30e9\u30a4\u30d9\u30fc\u30c8\u3067\u4f5c\u3063\u3066\u3044\u308bWEB\u30b5\u30fc\u30d3\u30b9\u306e\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u3092\u4f5c\u308b\u306b\u3042\u305f\u3063\u3066\u3001Vue.js\uff0bTypeScript\u3092\u8a66\u3057\u3066\u307f\u308b\u3053\u3068\u306b\u3057\u305f\u3002 \u57fa\u672c\u7684\u306b\u306f\u516c\u5f0f\u30b5\u30a4\u30c8\u3092\u53c2\u7167\u3055\u305b\u3066\u3044\u305f\u3060\u3044\u305f\u3002 \u4f5c\u308b\u3082\u306e \u30e1\u30e2\u3092\u7de8\u96c6\u3059\u308b\u753b\u9762\u3092\u4f5c\u6210\u3059\u308b\u3002 \u521d\u671f\u8868\u793a \u30e1\u30e2\u8868\u793a\u6b04\u3068EDIT\u30dc\u30bf\u30f3\u304c\u8868\u793a\u3055\u308c\u3066\u3044\u308b \u30e1\u30e2\u8868\u793a\u6b04\u306b\u306f\u30e1\u30e2\u53d6\u5f97API\u3067\u53d6\u5f97\u3057\u305f\u30e1\u30e2\u306e\u5185\u5bb9\u3092\u8868\u793a\u3059\u308b API\u3067\u53d6\u5f97\u3059\u308b\u5185\u5bb9\u306f\u3053\u3093\u306a\u611f\u3058\u3002{ id: 123, body: "\u3053\u308c\u306f\u30b5\u30f3\u30d7\u30eb\u3067\u3059"} EDIT\u30dc\u30bf\u30f3\u30af\u30ea\u30c3\u30af \u8868\u793a\u6b04\uff0bEDIT\u30dc\u30bf\u30f3\u3092\u975e\u8868\u793a\u306b\u3057\u3001\u7de8\u96c6\u6b04\uff08textarea\uff09\uff0bSAVE\u30dc\u30bf\u30f3\u3092\u8868\u793a\u3059\u308b SAVE\u30dc\u30bf\u30f3\u30af\u30ea\u30c3\u30af \u7de8\u96c6\u6b04\uff0bSAVE\u30dc\u30bf\u30f3\u3092\u975e\u8868\u793a\u306b\u3057\u3001\u8868\u793a\u6b04\uff0bEDIT\u30dc\u30bf\u30f3\u3092\u8868\u793a\u3059\u308b \u30e1\u30e2\u4fdd\u5b58API\u3067\u30e1\u30e2\u3092\u4fdd\u5b58\u3059\u308b \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u4f5c\u6210 npm\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb \u4ee5\u524d\u8a18\u4e8b\u3092\u66f8\u3044\u305f\u306e\u3067\u3053\u3061\u3089\u3092\u53c2\u7167\u306e\u3053\u3068\u3002 node.js\u304a\u3088\u3073npm <\/span>Continue Reading<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[25,21],"tags":[],"_links":{"self":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts\/386"}],"collection":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/comments?post=386"}],"version-history":[{"count":1,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts\/386\/revisions"}],"predecessor-version":[{"id":387,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts\/386\/revisions\/387"}],"wp:attachment":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/media?parent=386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/categories?post=386"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/tags?post=386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}
\n\u57fa\u672c\u7684\u306b\u306f\u516c\u5f0f\u30b5\u30a4\u30c8<\/a>\u3092\u53c2\u7167\u3055\u305b\u3066\u3044\u305f\u3060\u3044\u305f\u3002<\/p>\n\u4f5c\u308b\u3082\u306e<\/h2>\n
\n
\n
{ id: 123, body: "\u3053\u308c\u306f\u30b5\u30f3\u30d7\u30eb\u3067\u3059"}<\/code><\/li>\n<\/ul>\n<\/li>\n
\n
\n
\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u4f5c\u6210<\/h2>\n
npm\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n
\nnode.js\u304a\u3088\u3073npm\u306eTips<\/a><\/p>\nvue-cli\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n
npm install -g @vue\/cli<\/code><\/pre>\n
\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210<\/h5>\n
vue create frontend<\/code><\/pre>\n
? Please pick a preset: Manually select features\n? Check the features needed for your project: Babel, TS, Linter\n? Use class-style component syntax? Yes\n? Use Babel alongside TypeScript for auto-detected polyfills? Yes\n? Pick a linter \/ formatter config: Standard\n? Pick additional lint features: (Press <space> to select, <a> to toggle all, <i\n> to invert selection)Lint on save\n? Where do you prefer placing config for Babel, PostCSS, ESLint, etc.? In dedica\nted config files\n? Save this as a preset for future projects? (y\/N) N<\/code><\/pre>\n
\n
Eslint Standard<\/code>\u3092linter\u306b\u6307\u5b9a\u3057\u3066\u3044\u308b\u3002<\/li>\n<\/ul>\n
\u30a2\u30d7\u30ea\u8d77\u52d5<\/h3>\n
cd frontend\nnpm run serve<\/code><\/pre>\n
\nhttp:\/\/localhost:8081\/<\/a><\/p>\n\u81ea\u52d5\u751f\u6210\u3055\u308c\u305f\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u7fa4\u306e\u8aac\u660e<\/h2>\n
.browserslistrc<\/h3>\n
\n\u4e0b\u8a18\u8a2d\u5b9a\u306f\u3001\u30d6\u30e9\u30a6\u30b6\u306e\u5229\u7528\u30b7\u30a7\u30a2\u304c1%\u3088\u308a\u5927\u304d\u304f\u3001\u304b\u3064\u3001\u76f4\u8fd12\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u30bf\u30fc\u30b2\u30c3\u30c8\u3068\u3057\u3066\u6307\u5b9a\u3057\u3066\u3044\u308b\u3002
\n\u8a73\u7d30\u306f\u3053\u3061\u3089<\/a>\u3092\u53c2\u7167\u306e\u3053\u3068\u3002<\/p>\n> 1%\nlast 2 versions<\/code><\/pre>\n
.editorconfig<\/h3>\n
\n\u30d5\u30a1\u30a4\u30eb\u4fdd\u5b58\u6642\u306b\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3055\u308c\u308b\u3088\u3046\u306b\u3059\u308b\u306b\u306f\u4ee5\u4e0b\u306e\u4f5c\u696d\u3092\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002<\/p>\n\n
\n
"<\/code>->
'<\/code>\u5909\u63db\u3084\u884c\u672b\u306b
;<\/code>\u8ffd\u52a0\u306a\u3069\u3044\u3089\u3093\u3053\u3068\u3092\u3059\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3057\u307e\u3046<\/li>\n
\n\u8a73\u7d30\u306f\u3053\u3061\u3089<\/a>\u3092\u53c2\u7167\u306e\u3053\u3068\u3002<\/p>\n[*.{js,jsx,ts,tsx,vue}]\nindent_style = space\nindent_size = 2\ntrim_trailing_whitespace = true\ninsert_final_newline = true<\/code><\/pre>\n
.eslintrc.js<\/h3>\n
\nEsLint\u3092\u5b9f\u884c\u3059\u308b\u65b9\u6cd5\u306f\u3044\u304f\u3064\u304b\u3042\u308b\u3002<\/p>\n\n
npm run serve<\/code>\u3092\u5b9f\u884c\u3059\u308b\u3002\u30b5\u30fc\u30d0\u304c\u7acb\u3061\u4e0a\u304c\u308a\u30d5\u30a1\u30a4\u30eb\u304c\u4fdd\u5b58\u3055\u308c\u308b\u305f\u3073\u306beslint\u304c\u8d70\u308b\u3002<\/li>\n
npm run lint<\/code>\u3092\u5b9f\u884c\u3059\u308b\u3002<\/li>\n
ESlint<\/code>\u62e1\u5f35\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\uff08\u30c7\u30d5\u30a9\u30eb\u30c8\u3067Settings\u306e
Eslint: Enable<\/code>\u306b\u306a\u3063\u3066\u3044\u308b\u3002\uff09<\/li>\n<\/ul>\n
module.exports = {\n root: true, \/\/ \u3053\u306e\u30d5\u30a9\u30eb\u30c0\u304croot\u3060\u3068\u3044\u3046\u6307\u5b9a\u3002\u3064\u307e\u308a\u89aa\u30d5\u30a9\u30eb\u30c0\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u63a2\u3057\u306b\u884c\u304b\u306a\u3044\n env: {\n node: true \/\/ \u4e8b\u524d\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\u3092Node.js\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\u306b\u3059\u308b\u3002`browser`\u306a\u3069\u3082\u6307\u5b9a\u53ef\u80fd\u3002\n },\n 'extends': [ \/\/ vue\u7528\u306e\u62e1\u5f35\u3002\u57fa\u672c\u3053\u308c\u306b\u5f93\u3063\u3066\u304a\u3051\u3070\u3044\u3044\u306e\u3060\u3068\u601d\u3046\u3002\n 'plugin:vue\/essential',\n '@vue\/standard',\n '@vue\/typescript'\n ],\n rules: { \n 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off', \/\/ production\u306e\u5834\u5408\u306ferror\u30ec\u30d9\u30eb\u3067\u51fa\u529b\u3002\u305d\u308c\u4ee5\u5916\u306f\u666e\u901a\u306b\u51fa\u529b\n 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'\n },\n parserOptions: {\n parser: '@typescript-eslint\/parser' \/\/ typescript\u7528\u306eparser\u3092\u6307\u5b9a\n }\n}<\/code><\/pre>\n
.gitignore<\/h3>\n
babel.config.js<\/h3>\n
\n\u3053\u3053\u3067\u306fvue\u7528\u306e\u30d7\u30ea\u30bb\u30c3\u30c8\u304c\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u3002\u8a73\u7d30\u306f\u3053\u3061\u3089<\/a>\u3092\u53c2\u7167\u306e\u3053\u3068\u3002<\/p>\nmodule.exports = {\n presets: [\n '@vue\/app'\n ]\n}<\/code><\/pre>\n
package.json<\/h3>\n
\n\u8a73\u7d30\u306f\u3053\u3061\u3089<\/a>\u3092\u53c2\u7167\u306e\u3053\u3068\u3002<\/p>\n{\n "name": "frontend",\n "version": "0.1.0",\n "private": true,\n "scripts": {\n "serve": "vue-cli-service serve", \/\/ \u30a2\u30d7\u30ea\u3092\u8d77\u52d5\u3059\u308b\u30bf\u30b9\u30af\n "build": "vue-cli-service build", \/\/ production\u7528\u306bjavascript\u3092\u30b3\u30f3\u30d1\u30a4\u30eb\u3059\u308b\u30bf\u30b9\u30af\n "lint": "vue-cli-service lint" \/\/ lint\u3092\u5b9f\u884c\u3059\u308b\u30bf\u30b9\u30af\n },\n "dependencies": {\n "core-js": "^2.6.5",\n "vue": "^2.6.10",\n (\u7701\u7565)\n },\n "devDependencies": {\n "@vue\/cli-plugin-babel": "^3.7.0",\n (\u7701\u7565)\n }\n}<\/code><\/pre>\n
postcss.config.js<\/h3>\n
\n\u4eca\u56de\u306fVuetify\u3092\u5229\u7528\u3059\u308b\u306e\u3067\u3001\u72ec\u81ea\u306b\u30b9\u30bf\u30a4\u30eb\u3092\u5b9a\u7fa9\u3057\u306a\u3044\u65b9\u91dd\u3002
\n\u8a73\u7d30\u306f\u3053\u3061\u3089<\/a>\u3092\u53c2\u7167\u306e\u3053\u3068\u3002<\/p>\nmodule.exports = {\n plugins: {\n autoprefixer: {}\n }\n}<\/code><\/pre>\n
tsconfig.json<\/h3>\n
{\n "compilerOptions": {\n "target": "esnext",\n "module": "esnext",\n "strict": true, \/\/ strict\u30e2\u30fc\u30c9\n "jsx": "preserve",\n "importHelpers": true,\n "moduleResolution": "node",\n "experimentalDecorators": true,\n "esModuleInterop": true,\n "allowSyntheticDefaultImports": true,\n "sourceMap": true, \/\/ map\u30d5\u30a1\u30a4\u30eb\u3092\u51fa\u529b\u3059\u308b\n "baseUrl": ".",\n "types": [\n "webpack-env"\n ],\n "paths": {\n "@\/*": [\n "src\/*" \/\/ \u30e9\u30f3\u30bf\u30a4\u30e0\u306b\u304a\u3044\u3066\u3001"@\/hoge" -> ".\/src\/hoge"\u3068\u3057\u3066\u30d1\u30b9\u3092\u89e3\u6c7a\u3059\u308b\n ]\n },\n "lib": [ \/\/ \u30b3\u30f3\u30d1\u30a4\u30eb\u306b\u542b\u3081\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30ea\u30b9\u30c8\n "esnext",\n "dom",\n "dom.iterable",\n "scripthost"\n ]\n },\n "include": [ \/\/ \u30b3\u30f3\u30d1\u30a4\u30eb\u5bfe\u8c61\u306e\u30d5\u30a1\u30a4\u30eb\n "src\/**\/*.ts",\n "src\/**\/*.tsx",\n "src\/**\/*.vue",\n "tests\/**\/*.ts",\n "tests\/**\/*.tsx"\n ],\n "exclude": [ \/\/ \u5bfe\u8c61\u5916\u306b\u3059\u308b\u30d5\u30a9\u30eb\u30c0\n "node_modules"\n ]\n}<\/code><\/pre>\n
\u5165\u308c\u3066\u304a\u3044\u305f\u65b9\u304c\u3044\u3044VS Code\u306e\u62e1\u5f35<\/h2>\n
\n
Vetur<\/code>\u62e1\u5f35\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b<\/li>\n
Editor Config for VS Code<\/code>\u62e1\u5f35\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b<\/li>\n<\/ul>\n
\u5b9f\u88c5Tips<\/h2>\n
Vue\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306b\u5916\u90e8\u304b\u3089\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u6e21\u3059<\/h3>\n
main.ts<\/code>\u306b\u3066
ComponentOptions<\/code>\u306e\u5b9a\u7fa9\u3092\u3059\u308c\u3070\u826f\u3044\u3002
\n\u4e0b\u8a18\u30b5\u30f3\u30d7\u30eb\u306f\u3001url<\/code>\u3068\u3044\u3046\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u30aa\u30d7\u30b7\u30e7\u30f3\u3068\u3057\u3066\u8ffd\u52a0\u3057\u3066\u3044\u308b\u3002
?:<\/code>\u3067\u5b9a\u7fa9\u3057\u306a\u3044\u3068\u30a8\u30e9\u30fc\u306b\u306a\u308b\u306e\u3067\u6ce8\u610f\u3002 <\/p>\n
import Vue from 'vue'\nimport App from '.\/App.vue'\n\nVue.config.productionTip = false\n\n\/\/ \u3053\u3053\u3067ComponentOptions\u306burl\u3068\u3044\u3046\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u8ffd\u52a0\u3057\u3066\u3044\u308b\ndeclare module 'vue\/types\/options' {\n interface ComponentOptions<V extends Vue> {\n url?: string\n }\n}\n\n\/\/ url\u3068\u3044\u3046\u30aa\u30d7\u30b7\u30e7\u30f3\u306b\u5024\u3092\u6e21\u3057\u3066\u3044\u308b\u3002\nnew Vue({\n url: 'http:\/\/rinoguchi.com\/hoge\/fuga',\n render: h => h(App)\n}).$mount('#app')<\/code><\/pre>\n
export default class App extends Vue {\n private url?: string = this.$root.$options.url\n}<\/code><\/pre>\n
\u5b50\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304b\u3089\u89aa\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u51e6\u7406\u3092\u547c\u3073\u51fa\u3059<\/h3>\n
loggedIn<\/code>\u30d7\u30ed\u30d1\u30c6\u30a3\u3092
true<\/code>\u306b\u3059\u308b\u3068\u3044\u3046\u30b1\u30fc\u30b9\u3092\u8aac\u660e\u3059\u308b\u3002<\/p>\n
Login<\/code>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u3066\u3001
@Emit<\/code>\u3092\u4f7f\u3063\u3066
succeeded<\/code>\u30a4\u30d9\u30f3\u30c8\u3092\u5b9a\u7fa9\u3059\u308b\u3002
\n\u4e0b\u8a18\u30b5\u30f3\u30d7\u30eb\u3067\u306f\u3001login<\/code>\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3057\u305f\u3089\u3001\u30ed\u30b0\u30a4\u30f3\u51e6\u7406\u304c\u5b9f\u884c\u3055\u308c\u3001\u51e6\u7406\u304c\u7d42\u308f\u3063\u305f\u3089
this.succeeded()<\/code>\u3092\u5b9f\u884c\u3057\u3066\u3044\u308b\u3002 <\/p>\n
<template>\n <div>\n <button @click=login>login<\/button>\n <\/div>\n<\/template>\n\n<script lang="ts">\n@Component\nexport default class Login extends Vue {\n @Emit() private succeeded () {}\n login () {\n \/\/ login\u51e6\u7406\u304c\u5b9f\u88c5\u3057\u3066\u3042\u308b\n (\u7701\u7565)\n \/\/ login\u51e6\u7406\u304c\u7d42\u308f\u3063\u305f\u3089succeeded\u3092\u5b9f\u884c\u3059\u308b\n this.succeeded()\n }\n}\n<\/script>\n<\/code><\/pre>\n
App<\/code>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u3066\u3001
Login<\/code>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e
@succeeded<\/code>\u30a4\u30d9\u30f3\u30c8\u306b\u5bfe\u3057\u3066
loginSucceeded()<\/code>\u3092\u7d10\u3065\u3051\u308b\u3002
\n\u3053\u308c\u306b\u3088\u308aLogin<\/code>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u3066
succeeded<\/code>\u30a4\u30d9\u30f3\u30c8\u304c\u767a\u706b\u3055\u308c\u305f\u3089\u3001\u89aa\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5074\u306e
loginSucceeded()<\/code>\u304c\u5b9f\u884c\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308b\u3002<\/p>\n
<template>\n <div id="app">\n <template v-if=loggedIn>\n <Memo>\n <\/template>\n <template v-else>\n <Login @succeeded=loginSucceeded \/>\n <\/template>\n <\/div>\n<\/template>\n\n<script lang="ts">\nexport default class App extends Vue {\n private loggedIn: boolean = false\n loginSucceeded (): void {\n this.loggedIn = true\n private url?: string = this.$root.$options.url\n }\n}\n<\/script><\/code><\/pre>\n
axios\u3092\u4f7f\u3063\u3066AJAX\u901a\u4fe1\u3092\u884c\u3046<\/h3>\n
\n\u4eca\u56de\u306f\u3001mounted<\/code>\u306b\u3066\u30e1\u30e2\u3092\u53d6\u5f97\u3059\u308bAPI\u3092\u547c\u3073\u51fa\u3057\u3001\u305d\u306e\u7d50\u679c\u3092\u753b\u9762\u306b\u63cf\u753b\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u308b\u3002<\/p>\n
npm install axios --save<\/code><\/pre>\n
\n
v-if<\/code>\u3092\u4f7f\u3063\u3066API\u3067\u30e1\u30e2\u3092\u53d6\u5f97\u3059\u308b\u307e\u3067\u306f
loading...<\/code>\u3092\u8868\u793a\u3057\u3001\u53d6\u5f97\u3057\u305f\u3089
memo<\/code>\u3092\u63cf\u753b\u3057\u3066\u3044\u308b\u3002<\/li>\n
@Prop<\/code>\u3067\u89aa\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304b\u3089\u6e21\u3063\u3066\u304d\u305f
memoId<\/code>\u3092\u30d7\u30ed\u30d1\u30c6\u30a3\u3068\u3057\u3066\u5b9a\u7fa9\u3057\u3066\u3044\u308b\u3002<\/li>\n
mounted<\/code>\u306b\u3066API\u3092\u547c\u3073\u51fa\u3057\u3066\u3044\u308b\u3002\n
\n
memo<\/code>\u3092\u30d7\u30ed\u30d1\u30c6\u30a3\u306e
memo<\/code>\u306b\u8a2d\u5b9a\u3057\u3066\u3044\u308b<\/li>\n
finally<\/code>\u3067
this.loading = false<\/code>\u3092\u8a2d\u5b9a\u3057\u3001\u30e1\u30e2\u304c\u8868\u793a\u3055\u308c\u308b\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n
<template>\n <div>\n <template v-if=loading>\n <pre>loading...<\/pre>\n <\/template>\n <template v-else>\n <pre>{{ memo }}<\/pre> \n <\/template> \n <\/div>\n<\/template>\n\n<script lang="ts">\nexport default class Memo extends Vue {\n @Prop() private memoId!: string\n private loading: boolean = false\n private memo?: string\n\n mounted (): void = {\n axios\n .get(`http:\/\/rinoguchi.com\/memos`, { params: { id: this.memoId } })\n .then(response => {\n if (response.status !== 200) {\n alert('api call error')\n return\n }\n this.body = response.data.body\n })\n .finally(() => {\n this.loading = false\n })\n }\n}<\/code><\/pre>\n
typescript\u3092\u4f7f\u3063\u3066\u3044\u308b\u306e\u3067Model\u30af\u30e9\u30b9\u3092\u5b9a\u7fa9\u3057\u3066\u307f\u308b<\/h3>\n
id<\/code>\u3068
body<\/code>\u306e\u4e8c\u3064\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u6301\u3064
MemoModel<\/code>\u3092\u5b9a\u7fa9\u3057\u3066\u307f\u3088\u3046\u3068\u601d\u3046\u3002
\n\u3044\u304f\u3064\u304b\u306e\u5b9a\u7fa9\u30d1\u30bf\u30fc\u30f3\u304c\u8003\u3048\u3089\u308c\u308b\u306e\u3067\u3001\u89e3\u8aac\u3057\u3088\u3046\u3068\u601d\u3046\u3002<\/p>\nundefined<\/code>\u3067\u3082OK\u306a\u5834\u5408<\/p>\n
class MemoModel {\n id?: number\n body?: string\n}\n\nconst memo = new MemoModel()\nconsole.log(memo.body) \/\/ -> undefined\nmemo.body = 'xyz'\nconsole.log(memo.body) \/\/ -> 'xyz'<\/code><\/pre>\n
undefinded<\/code>\u3060\u3068\u56f0\u308b\u3051\u3069\u3001\u521d\u671f\u5024\u3092\u8a2d\u5b9a\u3067\u304d\u308b\u5834\u5408<\/p>\n
class MemoModel {\n id: number = -1\n body: string = 'default'\n}\n\nconst memo = new MemoModel()\nconsole.log(memo.body) \/\/ -> `default`\nmemo.body = 'xyz'\nconsole.log(memo.body) \/\/ -> 'xyz'<\/code><\/pre>\n
undefinded<\/code>\u3060\u3068\u56f0\u308b\u3051\u3069\u3001\u521d\u671f\u5024\u3092\u8a2d\u5b9a\u3067\u304d\u306a\u3044\u5834\u5408<\/p>\n
class MemoModel {\n id: number = -1\n body: string = 'default'\n constructor(theId: number, theBody: string) {\n this.id = theId\n this.body = theBody\n }\n}\n\nconst memo = new MemoModel(123, 'xyz')\nconsole.log(memo.body) \/\/ -> `xyz`<\/code><\/pre>\n
undefinded<\/code>\u3060\u3068\u56f0\u308b\u3051\u3069\u3001\u521d\u671f\u5024\u306f\u8a2d\u5b9a\u3057\u3066\u3082\u554f\u984c\u306a\u304b\u3063\u305f\u306e\u3067\u3001\uff12.\u306e\u30d1\u30bf\u30fc\u30f3\u3067\u5b9f\u88c5\u3057\u305f\u3002
\n\u3082\u3061\u308d\u3093\u3001Model\u30af\u30e9\u30b9\u306f\u5225\u30d5\u30a1\u30a4\u30eb\u3067\u5b9a\u7fa9\u3057\u3066\u3001import\u3057\u3066\u4f7f\u3063\u3066\u3082\u826f\u3044\u3002<\/p>\n<template>\n <div>{{ memo.body }}<\/div>\n<\/template>\n\n<script lang="ts">\nclass MemoModel {\n id: number = -1\n body: string = 'default'\n}\n\n@Component\nexport default class Memo extends Vue {\n private memo: MemoModel = new MemoModel()\n\n mounted (): void {\n axios\n .get(`http:\/\/rinoguchi.com\/memos\/latest`)\n .then(response => {\n if (response.status !== 200) {\n alert('api call error')\n return\n }\n this.memo.id = response.data.id\n this.memo.body = response.data.body\n })\n .finally(() => {\n this.loading = false\n })\n }\n}<\/code><\/pre>\n
\u74b0\u5883\u5909\u6570\u3092\u8aad\u307f\u8fbc\u3080<\/h3>\n
\n
\n.env.local # loaded in all cases, ignored by git
\n.env.[mode] # only loaded in specified mode
\n.env.[mode].local # only loaded in specified mode, ignored by git <\/p>\n<\/blockquote>\ndevelopmemt<\/code>\u30e2\u30fc\u30c9\u3067\u52d5\u304b\u3057\u3066\u3044\u308b\u969b\u306e\u74b0\u5883\u5909\u6570\u3092\u5b9a\u7fa9\u3057\u305f\u3002
\n\u5909\u6570\u540d\u306fVUE_APP<\/code>\u3067\u59cb\u307e\u3063\u3066\u3044\u308b\u5fc5\u8981\u304c\u3042\u308b\u306e\u3067\u8981\u6ce8\u610f!!<\/p>\n
.env.development<\/code>\u306b\u3066\u7ba1\u7406\u3059\u308b\u3053\u3068\u306b\u3057\u305f\u3002 <\/p>\n
VUE_APP_BASE_URL=https:\/\/rinoguchi.com\/<\/code><\/pre>\n
.env.development.local<\/code>\u306b\u3066\u7ba1\u7406\u3059\u308b\u3053\u3068\u306b\u3057\u305f\u3002<\/p>\n
VUE_APP_GOOGLE_CLIENT_ID=***********.apps.googleusercontent.com<\/code><\/pre>\n
process.env<\/code>\u3092\u4f7f\u3063\u3066\u3069\u3053\u304b\u3089\u3067\u3082\u5229\u7528\u3067\u304d\u308b\u3002<\/p>\n
console.log(process.env.VUE_APP_BASE_URL)\nconsole.log(process.env.VUE_APP_GOOGLE_CLIENT_ID)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"