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>