Vue.js - exercise1
by hyeyoon
HTML
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<div id="exercise">
<!-- 1) Fill the <p> below with your Name and Age - using Interpolation -->
<p>VueJS is pretty cool - {{ name }} ({{ age }})</p>
<!-- 2) Output your age, multiplied by 3 -->
<p>{{ tripleAge() }}</p>
<!-- 3) Call a function to output a random float between 0 and 1 (Math.random()) -->
<p>{{ randomNumber() }}</p>
<!-- 4) Search any image on Google and output it here by binding the "src" attribute -->
<div>
<img style="width:100px;height:100px" :src="imageLink">
</div>
<!-- 5) Pre-Populate this input with your name (set the "value" attribute) -->
<div>
<input type="text" :value="name">
</div>
</div>
JavaScript
new Vue({
el: '#exercise',
data: {
name: 'Hyeyoon',
age: 24,
imageLink: "https://ichef.bbci.co.uk/news/660/cpsprodpb/16620/production/_91408619_55df76d5-2245-41c1-8031-07a4da3f313f.jpg"
},
methods: {
tripleAge: function() {
return this.age * 3;
},
randomNumber: function() {
return Math.random();
}
}
});