Error : document.queryselector is not a function

Error : document.queryselector is not a function

在下面的代码中,标有 添加更多 的按钮未按预期运行。理想情况下,它应该将输入值添加到页面上的无序列表中。相反,我收到以下错误:

Uncaught TypeError: document.queryselector is not a function

页面代码

<div id="root">
    <input type="text" id="input" v-model="message"/>

    <p>The value of the input is : {{message}}</p>

    <ul>
        <li v-for="n in names" v-text="n"></li>
    </ul>

    <input id="input1" type="text"/>

    <button id="button"> Add More </button>
</div>

<script>
    var app = new Vue ({
        el : '#root',
        data : {
            message : 'Hello World!',
            favourite : 'author',
            names : ['Sunil' , 'Anis' , 'Satyajit']
        },
    });

    document.queryselector('#button').addEventListener('click', function(event) {
        var n = document.queryselector('#input1');
        app.names.push(n.value);
        n.value = '';
    });

</script>

document.querySelector。注意 querySelector.

中的大写 S

您还有 addEventListner 的拼写错误。应该是 addEventListener.