Solution to Failure to Obtain an Input Value

Viewed 44

When I entered a value in the input box and submitted it, the mandatory item verification failed, and the system displayed a message indicating that a parameter was empty and instructed me to enter a value. The code for obtaining the input value is as follows: (see the solution in column C) can you give me some advice about it?

1 Answers

The possible cause is that the method for obtaining the value is incorrect. As a result, the value in the input box cannot be obtained.

Use the onchange event to assign a value to the model and obtain the value of the input box. The method is as follows:

  1. Initialize the model.
   data:{
       accountValue:''
   }
  1. Bind an event to the input box.
  <input @change="getAccountValue" value="{{accountValue}}"></input>
  1. Assign a value.
getAccountValue: function(e) {
       this.accountValue = e.value // Here, e.value instead of e.target.attr.value is used.
   }

Refer to the official document instead of generating a JavaScript object for coding. A JavaScript object may lead to compatibility issues. Currently, the data binding mode of the quick app is unidirectional.

  1. The value entered in the input box does not change the value of accountValue in data.

  2. If the value of the input box is changed by setting this.accountValue to xxx, the onchange event of the input will not be triggered.

  3. In this.accountValue = xxx format, if the value of accountValue before and after the change is the same, the page will not be re-rendered.

Related