优化 localizeText, 可以接受 string 参数并直接返回。
This commit is contained in:
		
							parent
							
								
									6fa099771a
								
							
						
					
					
						commit
						941001c098
					
				
							
								
								
									
										12
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								index.js
									
									
									
									
									
								
							@ -41,12 +41,14 @@ module.exports = {
 | 
				
			|||||||
  localizeText(i18nText) {
 | 
					  localizeText(i18nText) {
 | 
				
			||||||
    // 如果直接挂载到 Vue.prototype 下,那么可以直接访问 this.i18nText。但如果通过 this.$T.localeText 访问,那么 this.i18nText 就报错了。因此安全起见,先获取当前 page
 | 
					    // 如果直接挂载到 Vue.prototype 下,那么可以直接访问 this.i18nText。但如果通过 this.$T.localeText 访问,那么 this.i18nText 就报错了。因此安全起见,先获取当前 page
 | 
				
			||||||
    const thisPage = getCurrentPages()[getCurrentPages().length - 1]
 | 
					    const thisPage = getCurrentPages()[getCurrentPages().length - 1]
 | 
				
			||||||
    if (thisPage.$store?.state?.i18n?.mylang) {
 | 
					    if (i18nText && typeof(i18nText)==='object' && thisPage.$store?.state?.i18n?.mylang) {
 | 
				
			||||||
      if (typeof(i18nText)==='object' && i18nText && i18nText[thisPage.$store.state.i18n.mylang]){
 | 
					      return i18nText[thisPage.$store.state.i18n.mylang] || ''
 | 
				
			||||||
        return i18nText[thisPage.$store.state.i18n.mylang]
 | 
					 | 
				
			||||||
      }else if (typeof(i18nText)==='undefined') {
 | 
					 | 
				
			||||||
        return thisPage.i18nText[thisPage.$store.state.i18n.mylang]
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    if (!i18nText && typeof(thisPage.i18nText)==='object' && thisPage.$store?.state?.i18n?.mylang) {
 | 
				
			||||||
 | 
					      return thisPage.i18nText[thisPage.$store.state.i18n.mylang] || ''
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (typeof i18nText === 'string'){
 | 
				
			||||||
 | 
					      return i18nText
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return ''
 | 
					    return ''
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user