两个input组件用data-type形式传参,value会相互覆盖?

小程序 文章 2022-02-09 14:20 409 0 全屏看文

AI助手支持GPT4.0

两个input组件用data-type形式传参,value会相互覆盖?Two input components pass parameters in the form of data-type, will the values ​​overwrite each other?

两个input组件用data-type形式传参,value会相互覆盖?

wxml:

<view>  <input type="text" value="{{value1}}" data-type="type1" bindchange="changeData"/>  <input type="text" value="{{value2}}" data-type="type2" bindchange="changeData"/></view>

js:

data: {  value1: "",  value2: ""},changeData: function(e) {  var type = e.currentTarget.dataset.type  var value = e.detail.value  switch (type) {    case "type1":        this.setData({value1: value})        break;    case "type2":        this.setData({value2: value})        break;    default:      break;  }}  


两个组件会相互清空,即:填入第一个input组件后会清空第二个input组件的内容,填入第二个input组件后会清空第一个input组件的内容,有没有大佬解答一下?

wxml: js: data: { value1: "", value2: ""}, changeData: function(e) { var type = e.currentTarget.dataset.type var value = e.detail.value switch (type) { case "type1": this.setData({value1: value}) break; case "type2": this. setData({value2: value}) break; default: break; }} The two components will clear each other, that is, the contents of the second input component will be cleared after the first input component is filled, and the contents of the first input component will be cleared after the second input component is filled. Is there a big man to answer?

回答:

社区技术运营专员-horanzhou:

请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

微喵网络:

来个代码片段

自己调试看看

打印type

看看appdata面板

Mr.Zhao:

土豆炖白菜:刚刚编辑缓存问题,已补充
Mr.Zhao:你这代码复现不出来啊
土豆炖白菜:两个input在同一个view里面,会不会跟bindtab和catchtab一样有冒泡问题?
Mr.Zhao:你整个能复现问题的代码片段

-EOF-

AI助手支持GPT4.0