Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击按钮后,如何清除VueJS中的输入文本?_Javascript_Function_Input_Vue.js_Innerhtml - Fatal编程技术网

Javascript 单击按钮后,如何清除VueJS中的输入文本?

Javascript 单击按钮后,如何清除VueJS中的输入文本?,javascript,function,input,vue.js,innerhtml,Javascript,Function,Input,Vue.js,Innerhtml,我希望输入框中的文本在按下enter按钮并将addTask功能添加到列表中后立即清除。我尝试了document.getElementById(“inp”).innerHTML=“”,但没有成功。我该怎么做 HTML: 清除您的模型: addTask: function() { var task = this.newTask this.todoList.push(task) this.newTask

我希望输入框中的文本在按下enter按钮并将addTask功能添加到列表中后立即清除。我尝试了document.getElementById(“inp”).innerHTML=“”,但没有成功。我该怎么做

HTML:

清除您的模型:

addTask: function() {
                var task = this.newTask
                this.todoList.push(task)

                this.newTask = ''
            }

@这不是在Vue等框架中更改值的正确方法。您认为v-model对象无法正常工作的原因是什么?表示不清除值
var todo = new Vue({
    el: 'div#todo',
    data: {
        newTask:'',
        todoList: []
    },
    methods: {
        addTask: function() {
            var task = this.newTask
            this.todoList.push(task)
        },
        removeTask: function(task) {
            var index = this.todoList.indexOf(task)
            this.todoList.splice(index, 1)
        }

    }
})
addTask: function() {
                var task = this.newTask
                this.todoList.push(task)

                this.newTask = ''
            }