Skip to content

Instantly share code, notes, and snippets.

@danyn
Created October 28, 2021 19:33
Show Gist options
  • Save danyn/aff048b9efc3b08493a2cb2a62551f1a to your computer and use it in GitHub Desktop.
Save danyn/aff048b9efc3b08493a2cb2a62551f1a to your computer and use it in GitHub Desktop.
Watcher Exercise Problem
<div id="app">
<div>
<button @click="getTaco">
Click me to order a taco
</button>
<h2>{{order}}</h2>
<p v-if="orderStatus">{{ orderStatus }}</p>
<p></p>
</div>
</div>
const App = {
data() {
return {
orderStatus: 'Where is my taco...',
order: '',
orderSubmitted: null
}
},
methods: {
getTaco() {
this.order = 'Getting Taco.'
this.orderStatus = ''
}
},
watch: {
orderStatus(newVal, oldVal) {
setTimeout(()=>this.order = "🌮", 2000);
}
}
}
Vue.createApp(App).mount('#app')
<script src="https://unpkg.com/vue@next"></script>
#app {
margin: 30px;
}
button {
display: inline-block;
border: none;
padding: 0.75rem 1.5rem;
margin: 0;
text-decoration: none;
background: teal;
border-radius: 4px;
color: #ffffff;
font-family: sans-serif;
font-size: 1rem;
cursor: pointer;
text-align: center;
transition: background 250ms ease-in-out, transform 150ms ease;
-webkit-appearance: none;
-moz-appearance: none;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment