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.

Vue.js Basics

Last updated at Posted at 2021-07-22
index.html
   <section id="user-goal">
      <h2>My Course Goal</h2>
      <p>{{ courseGaol }}</p>
      <p>Learn more <a v-bind:href="vueLink">about Vue</a>.</p>
   </section>
app.js
const app = Vue.createApp({
    data() {
        return{
            courseGoalA: 'Finish the course and learn Vue!',
            courseGoalB: 'Master Vue and build amazing apps!',
            vueLink: 'https://v3.ja.vuejs.org/'
        };
    },
    methods: {
        outputGoal() {
            const ramdamNumber = Math.random();
            if (random < 0.5) {
                return this.courseGoalA;
            } else {
                return this.courseGoalB;
            }
        }
    }
});

app.mount('#user-goal');

sectionIdをapp.mount('')に入れる
#を忘れない!

returnの中にVueで管理するデータを書く

関数はmethodsの中に書く

htmlに書くときは{{}}の中に書く
urlの場合はv-bindを使う

metheds内でdataの値を使うときはthisをつける

index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vue Basics</title>
    <link
      href="https://fonts.googleapis.com/css2?family=Jost:wght@400;700&display=swap"
      rel="stylesheet"
    />
    <link rel="stylesheet" href="styles.css" />
    <script src="https://unpkg.com/vue@next" defer></script>
    <script src="app.js" defer></script>
  </head>
  <body>
    <header>
      <h1>Vue Course Goals</h1>
    </header>
    <section id="user-goal">
      <h2>My Course Goal</h2>
      <p>{{ courseGaol }}</p>
      <p>Learn more <a v-bind:href="vueLink">about Vue</a>.</p>
    </section>
  </body>
</html>

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?