Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

142
Visualizações
How to display this data from console.log(element.faculty_name) to template in vue?

I have the function of display data from major table on MySQL. I want to display the type of that major by comparing with the id of the faculty table like below. I have it displayed on console.log, how do I display it on the template?

Template tag

<td>
    {{ filterFaculty }}
</td>

Script tag

data() {
    return {
        majors:[],
        faculties:[],
        form: new Form({
            major_id:'',
            major_code:'',
            major_name:'',
            major_faculty:'',
            major_status: '',
        }),
    };
},
computed: {
    filterFaculty() {
        for(let i in this.majors) {
            this.faculties.forEach((element) => {
                if(element.faculty_code==this.majors[i].major_faculty) {
                    console.log(element.faculty_name);
                }else {
                    return '-';
                }
            });
        }
    }
},
mounted() {
    this.fetchFaculties();
    this.fetchMajors();
},
methods: {
  fetchFaculties(page_url) {
        let vm = this;
        page_url = '../../api/admin/edu-faculty/faculty/faculty';
        fetch(page_url)
        .then(res => res.json())
        .then(res => {
            this.faculties = res.data;
        })
        .catch(err => console.log(err));
    },
    fetchMajors(page_url) {
        let vm = this;
        page_url = '../../api/admin/edu-major/major/'+this.currentEntries+'?page='+this.pagination.current_page;
        fetch(page_url)
        .then(res => res.json())
        .then(res => {
            this.majors = res.data;
            this.pagination = res.meta;
        })
        .catch(err => console.log(err));
    },
 }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

There are different ways to achieve that, I think the easiest is to do following:

Define something in your data - like inputText and than set your element.faculty_name to this - like following:

data() {
  return {
    inputText: "",
  }
}

computed: {
    filterFaculty() {
        for(let i in this.majors) {
            this.faculties.forEach((element) => {
                if(element.faculty_code==this.majors[i].major_faculty) {
                    this.inputText = element.faculty_name; //Changed here
                }else {
                    return '-';
                }
            });
        }
    }
},

and than reference it in your template like this:

<td>
    {{ inputText }}
</td>

This should solve your problem!

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda