How to take the value of a reduce the tag to appear in the view - VUE.JS

Asked

Viewed 32 times

0

I’m trying to set up a panel, and I want to take the added values of a reduce to appear in the view

Inside the budgets, there’s an array of value, and I’ve done the methods to add

methods: {
open(os) {
  this.os = os.id;
  this.$axios
    .get(this.apiAtual + 
      "/Orcamento/GetOrcamentos/?" +
        qs.stringify({ os: this.os }, { arrayFormat: "repeat" })
    )
    .then(response => {
      this.readonly = $user.comercial ? false : response.data.readonly;
      if(os.situacao.id >= 3){
        this.readonly = true
      }
      this.orcamentos = response.data.orcamentos;
      this.loading = false;
    });
    },
  }, 

  Computed: {
      valor(){
        const ValorTotal = this.valor
        .reduce((acc, current) => 
          acc + current, 0);
        return ValorTotal;

        console.log(ValorTotal)
      }
    },
  data() {
    return {
      loading: false,
      search: false,
      cliente: null,
      projeto: null,
      situacao: null,
      tipos: null,
      orcamentos: [],
      especialidade: null

I would like the value to appear on that tag

    <div class="col-md-2 box box-primy">   
           <span> <p> TOTAL DE ORDEM DE SERVIÇO</p><br></span>
           <span> <h1> {{ValorTotal}}</h1> </span>
    </div> 
  • 1

    The name of the computed property is called valor and not ValorTotal, and the console.log that you have after Return is useless

  • then logic is right?

  • Apparently yes, it puts {{valor}} instead of {{ValorTotal}}. I didn’t test it, but that’s what I first noticed

  • good, as the value, belongs to the budget property, should not be this budget.value, or when you call the budget in array you already have freedom to take your internal values?

  • As I don’t know the structure of the variable this.valor I can’t help you, but the mistake at first glance I saw was what I said above

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.