Last active
April 20, 2024 18:33
-
-
Save dalaidunc/2a50a3580c1923d766fbc8170296e6e1 to your computer and use it in GitHub Desktop.
A simple example of a Vue single file component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div id="app"> | |
<ul> | |
<li v-for='number in numbers' :key='number'>{{ number }}</li> | |
</ul> | |
<form @submit.prevent='addNumber'> | |
<input type='text' v-model='newNumber'> | |
<button type='submit'>Add another number</button> | |
</form> | |
</div> | |
</template> | |
<script> | |
export default { | |
name: 'app', | |
methods: { | |
addNumber() { | |
const num = +this.newNumber; | |
if (typeof num === 'number' && !isNaN(num)) { | |
this.numbers.push(num); | |
} | |
} | |
}, | |
data() { | |
return { | |
newNumber: null, | |
numbers: [1, 23, 52, 46] | |
}; | |
} | |
} | |
</script> | |
<style lang="scss"> | |
ul { | |
padding: 0; | |
li { | |
list-style-type: none; | |
color: blue; | |
} | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment