Vue filter方法中的this


Vue filter方法中的this

项目开发时使用filter过滤数组时,在方法块里面不能使用this,否者会报undefined错误,经查阅过滤器的说用发现,是vue中的过滤器更偏向于对文本数据的转化,不能够一栏this上下文,所以如果需要使用到上下文的this,应该使用computed计算属性或者method方法

const tableData = this.memberData.filter(function (item) {

   return  item.cetfId === this.cetfId     //   输出this.cetfId为 undefined

     })

最简单的方法:定义一个参数传进去就好了

var cetfId=this.cetfId

const tableData = this.memberData.filter(function (item) {

   return  item.cetfId === cetfId

   })


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM