0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

グローバル登録でmain.jsで表示させてみる

Last updated at Posted at 2021-05-08

(1)templateに表示用HTMLを書く
(2)scriputにデータを入れる
(3)main.jsにファイルをimportする
(4)グローバル登録する

src/App.Aue
<template>
  <LikeNumber></LikeNumber>         #グローバル登録を別ファイルで表示
</template>
src/LikeNumber.Aue
<template>
  <p>いいね({{ number }})</p>
</template>

<script>
export default {
   data() {
     return {
       number: 7                          #データはここ
     };
   }
};
</script>
src/main.js
import Vue from 'vue';
import App from './App.vue';
import LikeNumber from './LikeNumber.vue';      //import

Vue.config.productionTip = false;
Vue.component("LikeNumber", LikeNumber);        //グローバル登録

new Vue({
  render: h => h(App)
}).$mount("#app");

20210508-122007.png

ちなみに今までと違ってフレームワークを使っているのでエラーをちゃんと表示してくれます。

参考

returnをretenと入力すると

Failed to compile.

./src/LikeNumber.vue
Module Error (from ./node_modules/eslint-loader/index.js):

/Users/maedatakuo/projects/udemy-vuejs/src/LikeNumber.vue
  8:11  error  Parsing error: Missing semicolon.

  2 | export default {
  3 |    date() {
> 4 |      retuen {
    |            ^
  5 |        number: 7
  6 |      };
  7 |    }

✖ 1 problem (1 error, 0 warnings)

やっとRuby on Railsのようなエラー表示が出て嬉しいです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?