Problem:
An input component is defined in the HTML file. The value attribute of the component is bound to a value. However, when the input content changes, the value obtained from the JS does not change.
Cause:
The data in the HarmonyOS project is unidirectionally bound. If the data is modified in the JS, the data is modified in the HTML file. If the data is modified in the reverse direction, the data cannot be synchronized.
Solution:
Define the change event in the input component. When the input content changes, the change event is triggered. In this case, obtain the current input value from the callback function of the change event and assign the value to the variable.
hml:
<input class="flex" id="input3" type="date" value="{{ inputVal }}" @change="changeInput" />Copy codeCopy code
JS:
data: {
inputVal:'InputValText'
},
changeInput(obj){
this.inputVal = obj.value
}
Top comments (0)