We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
在做分页组件时,我想在设置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; } } }
The text was updated successfully, but these errors were encountered:
不建议在 coerce 函数内做这样的操作(其本意只是用于类型转换)。另外因为 props 是先于组件本身的的 data 被初始化的,所以初始化的时候你并不能获得组件本身的 data。
可以做一个 computed property。
Sorry, something went wrong.
@yyx990803 如果我希望通过props传一些配置项(比如最大值或者最小值),然后通过coerce来校验,这种情况还是有必要把this指向$vm的。
No branches or pull requests
在做分页组件时,我想在设置curIndex的时候对其进行校验,但我不想在watch去处理,因为这样会触发多次,但是this的指向是window,是否有可以将其指向到$vm呢?
The text was updated successfully, but these errors were encountered: