我正在撰寫函式以查看學院的詳細資訊,它顯示了該學院的專業數量。我不知道如何用 v-if 和 v-for 計算陣列專業。請幫我解決這個問題。非常感謝。
模板標簽
<tr>
<td>Sumary:
<strong v-for="major in majors">
<strong v-if="form.faculty_code==majors.major_faculty">
{{ major }}
</strong>
</strong>
</td>
</tr>
腳本標簽
data() {
return {
faculties:[],
majors:[],
form: new Form({
faculty_id:'',
faculty_code:'',
faculty_name:'',
faculty_status: '',
}),
};
},
mounted() {
this.fetchMajors();
this.fetchFaculties();
},
methods: {
fetchFaculties(page_url) {
let vm = this;
page_url = '../../api/admin/edu-faculty/faculty/' this.currentEntries '?page=' this.pagination.current_page;
fetch(page_url)
.then(res => res.json())
.then(res => {
this.faculties = res.data;
this.pagination = res.meta;
})
.catch(err => console.log(err));
},
fetchMajors(page_url) {
let vm = this;
page_url = '../../api/admin/edu-major/chuyen-nganh/major';
fetch(page_url)
.then(res => res.json())
.then(res => {
this.majors = res.data;
})
.catch(err => console.log(err));
},
}
uj5u.com熱心網友回復:
要僅獲取具有給定教員代碼的專業數量,您可以在 mount() 函式中使用
this.total.majors = 0;
this.majors.forEach((element) => {
element.major_faculty == this.faculty_code ? this.total_majors = 1 : ""
});
uj5u.com熱心網友回復:
感謝您的觀看和幫助我。我已經找到了解決方案。
模板標簽
<tr>
<td>Sumary:
<strong>
{{ countA.length }}
</strong>
</td>
腳本標簽
computed: {
countA() {
return this.majors.filter(major => major.major_faculty==this.form.faculty_code);
}
},
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/353943.html
