vue+filter过滤器(多参数)传参 - 代码篇

vue+filter过滤器(多参数)传参 - 代码篇


传1个参数

//html
{{a1 | filterAa}}
//js
filters:{
  filterAa(a1){
    // a1是传入的参数
  }
}

传2个参数

//html
{{a1 | filterAa(a2)}}
//js
filters:{
  filterAa(a1,a2){
    // a1是传入的第一个参数
    // a2是传入的第二个参数
  }
}

传3个参数

//html
{{a1 | filterAa(a2,a3)}}
//js
filters:{
  filterAa(a1,a2,a3){
    // a1是传入的第一个参数
    // a2是传入的第二个参数
    // a3是传入的第三个参数
  }
}

传多个参数(3+)

//html
{{a1 | filterAa(a2,a3,···an···)}}
//js
filters:{
  filterAa(a1,a2,a3,···an···){
    // a1是传入的第一个参数
    // a2是传入的第二个参数
    // a3是传入的第三个参数
    
    // 以此类推    
    // an是传入的第n个参数
    
  }
}

猜你喜欢

转载自blog.csdn.net/qq_35393869/article/details/107913416