Skip to content

属性里coerce的this指向问题 #2218

Closed
@ivan403704409

Description

@ivan403704409

在做分页组件时,我想在设置curIndex的时候对其进行校验,但我不想在watch去处理,因为这样会触发多次,但是this的指向是window,是否有可以将其指向到$vm呢?

props:{
        // 当前页
        curIndex: {
            type: Number,
            default: 0,
            coerce: function (val) {
               //this --> window
               //i want -->  $vm
               if( val < 0 ){
                    val = 0;
                }else if(val>=this.total){
                    val = this.total - 1;
                }
                return val;
            }
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions