在vue的实例中,filter中编写过滤器会发现过滤器中的this指向了undefined,原因是过滤器的注册在 vue实例之前,this默认指向了window,因为严格模式指向了undefined,

解决:

一,使用计算属性替代

二,传入this

<template>
  <div>{value | formate(that)}}</div>
</template>

data () {
  return {
  that: this      
    }      
}

filters: {
  formate (val, obj) {
  return '0'+obj.methods(val)  
}  
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-08
  • 2021-08-10
  • 2021-10-29
猜你喜欢
  • 2022-01-10
  • 2022-12-23
  • 2021-07-15
  • 2021-10-22
  • 2021-12-11
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案