Problem Statement
I currently have a piece of code that involves updating the results-box
with a randomly chosen selection. I need to know how to modify the template when a @click
event occurs.
<template>
<div class="container">
<button @click="getDecision()" class="ui primary button">Discover</button>
<p id="results-box"></p>
</div>
</template>
<script>
export default {
name: "SlapButton",
data() {
return {
}
},
methods: {
getDecision: function () {
var decisions = [
"choice 1",
"choice 2",
"choice 3",
"choice 4",
"choice 5",
"choice 6"
]
var randNum = Math.floor((Math.random() * decisions.length) + 0);
var randChoice = decisions[randNum];
}
}
}
</script>
Question
Following a click event on the button, getDecision()
function is activated, and a random choice is selected from the decisions
array. How do I present this random choice randChoice
within the p
tag #results-box
.