filter中的this是全局的不是指向的vue实例,那么也就不能使用this.xxx
- 解决的方法
- 首先定义一个全局的变量
<script>
let that
export default {
}
</script>
- 然后在vue创建前的生命周期钩子函数中将that指向this
beforeCreate () {
that = this
}
- 然后就可以在filter中通过that访问vue实例了
filter中的this是全局的不是指向的vue实例,那么也就不能使用this.xxx
<script>
let that
export default {
}
</script>
beforeCreate () {
that = this
}