0
I’m developing an api on Vue.js that has a button to calculate the power of a certain number. But when I click the button it becomes static, nothing changes. You have to make some change in the method or some configuration in Vue?
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<div id="app">
<p>{{ numero }}</p>
<button @click="potencia">Potência 2*</button>
</div>
<script>
new Vue({
el:'#app',
data: {
numero: 3
},
methods: {
potencia() {
return Math.pow(this.numero, 2)
}
}
})
</script>
Your function returns the result of
Math.pow
. Where does this amount go? What would you like to do with the result?– Woss
The button should update the value of {{number }} inside the tag <p>. Ex: if {{number}} is 3, press the button and {{number}} is 9. Got it?
– at8819