Clearing input in vuejs form

后端 未结 7 2219
Happy的楠姐
Happy的楠姐 2020-12-14 09:06

Just completed a todolist tutorial. When submitting the form the input field doesn\'t clear.

After trying both:

    document.getElementById(\"todo-         


        
7条回答
  •  隐瞒了意图╮
    2020-12-14 09:20

    What you need is to set this.text to an empty string in your submitForm function:

    submitForm(e){
        this.todos.push(
            {
                text: this.text,
                completed: false
            }
        );
        this.text = "";
    
        // To prevent the form from submitting
        e.preventDefault();
    }
    

    Remember that binding works both ways: The (input) view can update the (string) model, or the model can update the view.

提交回复
热议问题