有一個陣列資料如下。我將對nav.陣列中傳入的資料資料進行操作,否則我將列印資料,我想知道我該怎么做?
title: item.title,
如果item.title在傳入的資料導航中。如果有 Let this.$t(item.title) 通過列印檢查。但如果沒有,nav.那么檢查是否this.$t(item.title)
menu_items: [
{
title: 'nav.home',
path: '/',
Index: 0
},
{
title: 'nav.gallery',
path: '/gallery',
order: 10
},
{
title: 'nav.contact',
path: '/contact',
order: 12
},
{
title: 'hello',
path: '/hello',
order: 13
},
{
title: 'hello2',
path: '/hello2',
order: 14
}
]
menuItem() {
return this.menu_items.map(item => {
return {
title: item.title,
path: item.path,
children: item.children,
order: item.order
}
}).sort((a, b) => a.order - b.order)
}
uj5u.com熱心網友回復:
您需要做的第一件事是搜索item.title item.title.search('nav.')
如果檢查后資料中沒有nav.,如果item.title存在,this.$t(item.title)
menuItem() {
return this.menu_items.map(item => {
return {
title: item.title.search('nav.') ? item.title : this.$t(item.title),
path: item.path,
children: item.children,
order: item.order
}
}).sort((a, b) => a.order - b.order)
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/463393.html
標籤:javascript
下一篇:在反應中僅更改單個元素類
