lundi 21 décembre 2020

How to make a sum of value in data with Vue.js and use it in of v-if?

I want to make a function to sum up the value in data with vue.js but I don't know how to code it.

var quiz = {
  questions: [
     {
        text: "who am I?",
        responses: [
           { text: "John", value: 1000 },
           { text: "James", value: 2000 },
           { text: "Lucy", value: 3000 },
           { text: "Mari", value: 4000 }
        ]
     },
     {
        text: "What do you want to be?",
        responses: [
           { text: "first selector", value: 10 },
           { text: "second selector", value: 20 },
           { text: "third selector", value: 30 },
           { text: "fourth selector", value: 40 }
        ]
     },
     {
        text: "How old are you?",
        responses: [
           { text: "first selector", value: 10 },
           { text: "second selector", value: 20 },
           { text: "third selector", value: 30 },
           { text: "fourth selector", value: 40 }
        ]
     }
  ]
}

and html code

<template v-if="resultOne">
                <p>First result</p>
</template>

I had a following data like this, and I want to make some v-if code by using the value of them. For example, if the sum of value become 1020, 1030, 1040, and 1050, I want to show "resultOne." How can I make a code like this?

Aucun commentaire:

Enregistrer un commentaire