Skip to content
New issue

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

vue2.0 点击上一页会报错 #7

Open
hotboys opened this issue May 17, 2017 · 7 comments
Open

vue2.0 点击上一页会报错 #7

hotboys opened this issue May 17, 2017 · 7 comments

Comments

@hotboys
Copy link

hotboys commented May 17, 2017

Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "cur"
这个得怎么解决 是双向绑定的问题吗

@romy2012
Copy link

确实存在这个问题。

@cycgit
Copy link
Owner

cycgit commented May 26, 2017

@hotboys @romy2012 是的 父子组件传递的时候 建议单向流

@hotboys
Copy link
Author

hotboys commented Jun 2, 2017

我已经解决了 需要props双向绑定,父组件需要增加个回调函数来接上一页下一页的回调,感谢楼主的组件

@xiaodongicon
Copy link

@hotboys 可以把最新的组件发我吗,我想参考下。

@hotboys
Copy link
Author

hotboys commented Jun 16, 2017

@vipsimple 怎么发给你 git 我不咋会用= =

@xiaodongicon
Copy link

@hotboys 你微信多少,我加你

@yangzheng0
Copy link

yangzheng0 commented Sep 3, 2019

这个问题就是因为在点击上一页下一页的时候子组件修改父组件的cur (当前页)导致的,我说一下我的解决办法吧, 楼主定义了一个btnClick方法,这个方法会在点击页码的时候生效,并将点击的页码传给父组件,我就重新定义一个btnClick1 方法, 对当前页减一,并传给父组件,替换掉原来直接cur-- 的操作.
代码如下
btnClick (page) {
if (page !== this.cur) {
this.callback(page)
}
},
btnClick1 (page) {
this.callback(this.cur + page)
}

然后 把上一页 方法改成 v-on:click="btnClick1(-1)" 下一页方法改成 v-on:click="btnClick1(1)"

github issues 无法帖html代码, 会被转换成页面 真的糟心,一点也不好用

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants