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

如何防止input内值双向绑定? #321

Closed
jimmyrogue opened this issue Aug 11, 2017 · 2 comments
Closed

如何防止input内值双向绑定? #321

jimmyrogue opened this issue Aug 11, 2017 · 2 comments

Comments

@jimmyrogue
Copy link

由于值有时候需要从localstroage取出来展示到input/textarea中,然后保存的时候又需要把这个值提交,所以代码类似这样

<input value={{name}} bindInput="{{oninput}}"> </input>

oninput(value){
 this.name = value.detail.value;
}

save(){
   request.post('xxx.com',{data:name})
}

onshow(){
let localname = localstorage.get('name');
this.name = localname;
}

问题在于,每次我想编辑内容的时候,比方说删除中间的某个值,因为会触发oninput的赋值,然后渲染页面,导致光标从中间跳到了input的最后。。。

有办法阻止渲染或者还是我只能多创造一个变量来保存?

@Gcaufy
Copy link
Collaborator

Gcaufy commented Aug 11, 2017

多弄一个变量吧。

@Gcaufy Gcaufy closed this as completed Aug 11, 2017
@hgl
Copy link

hgl commented May 5, 2018

假如有好几个input需要这样绑定,data 是一个字符串数组,每个字符串对应一个input,然后同时可以对数组做增加和删除操作。(类似添加/删除/修改联系人列表的效果)

多弄一个变量在这个场景下面好像没用了。有别的解决方案吗?

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

3 participants