Skip to content

Instantly share code, notes, and snippets.

@NickyMeuleman
Last active April 16, 2020 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NickyMeuleman/38f58a371f1685d9c01cfcb1c49b0cf9 to your computer and use it in GitHub Desktop.
Save NickyMeuleman/38f58a371f1685d9c01cfcb1c49b0cf9 to your computer and use it in GitHub Desktop.
<template>
<!-- pass in the "like" variable that corresponds to the input-value by using v-model -->
<form v-on:submit.prevent="onSubmit(like)">
<label
>What do you like:
<input v-model="like" />
</label>
<input type="submit" />
</form>
</template>
<script>
export default {
methods: {
onSubmit(thing = "turtles") {
console.log(`I like ${thing}.`);
// equivalent code that doesn't use an argument
// console.log(`I like ${this.like ?? "turtles"}.`);
},
},
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment