Vue.js componentを作成する

Vue.js componentを作成する

Vue.jsで、componentを作成するサンプルコードを記述してます。 「vue3」を使用してます。

環境

  • OS windows10 pro 64bit
  • Vue.js 3.2.2
  • Apache 2.4.43
  • ブラウザ chrome 92.0.4515.107

componentを作成

componentを作成するには、「component」を使用します。

以下は、 componentを作成して、テンプレートを表示するサンプルコードとなります。

※「vue3」は「cdn版」、デザインは「semantic-ui」を使用してます。

<!DOCTYPE html>
<html lang="ja">

<head>
  <meta charset="utf-8">
  <title>mebeeサンプル</title>
  <!-- semantic.css  -->
  <link rel="stylesheet" type="text/css"
    href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css">
  <script src="https://unpkg.com/vue@next"></script>

</head>
<style>
  body>.grid {
    height: 100%;
  }
</style>

<body>
  <div id="app" class="ui middle aligned center aligned grid">

    <div class="column">

      <test></test>

    </div>

  </div>
  <script>    

    Vue.createApp({})
    .component('test', {
      template: '<a class="ui red tag label">elm</a>'
    })
    .mount('#app')
    
  </script>
</body>

</html>

テンプレートが表示されていることが確認できます。