3
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.

Vue.jsに触れてみた

Last updated at Posted at 2021-04-06

Hello worldの表示

初めに動作確認のためhello worldを表示してみる。

sample.html
<head>
<meta charset="utf-8">
<title>Sample</title>
<!-- Vue.js の読み込み -->
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>

<div id="sample">{{ message }}</div>

<script>
    var sample = new Vue({
      el: '#sample',
      data: { message: 'Hello world!' }
    })
</script>
</body>

WS000004.JPG

HelloWorldが出た!

htmlでidを指定(ここではsample)を指定することでscript(el:'#sample)を呼び出し、
{{message}}部分にdata内容が表示される。

前回の続きだとcomponentsフォルダ直下にsample.vueを作成

components/sample.vue
<template>
    <div>
        <p>{{ text }}</p>
    </div>
</template>

<script>
export default {
    data(){
        return {
            text: "Hello_World!"
        }
    }
}
</script>
src/App.vue
<template>
  <div>
    <Sample></Sample>
  </div>
</template>

<script>
import Sample from './components/sample.vue'

export default {
  components:{
    Sample
  }
}
</script>

サーバ起動後
http://localhost:8080/

WS000006.JPG

3
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
3
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?