Blogger Information
Blog 47
fans 0
comment 2
visits 102743
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Vue项目i18n多语言国际化过程中,过滤器filter中使用国际化遇到的坑及解决办法。
拾一枝樱花的博客
Original
1366 people have browsed it

1.表格内的单元格数据,通过后台返回的字段对应的替换为filters中的文字。

  1. <template>
  2. <span>{{ scope.row.isMain | isMainFilter}}</span>
  3. </template>
  4. .......
  5. filters:{
  6. isMainFilter(isMain) {
  7. if (isMain) {
  8. return '是'
  9. } else {
  10. return '否'
  11. }
  12. }
  13. }

2.解决方案:

  1. <span>{{ scope.row.isMain | isMainFilter(te) }}</span>
  2. isMainFilter(isMain, te) {
  3. if (isMain) {
  4. return te('model.yes')
  5. } else {
  6. return te('model.no')
  7. }
  8. }

methods函数中定义

  1. te(arg) {
  2. const hasKey = this.$te(arg)
  3. if (hasKey) {
  4. const result = this.$t(arg)
  5. return result
  6. }
  7. return arg
  8. }
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post