Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.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 如何修复Vue JS警报_Javascript_Html_Vue.js_Vuejs2 - Fatal编程技术网

Javascript 如何修复Vue JS警报

Javascript 如何修复Vue JS警报,javascript,html,vue.js,vuejs2,Javascript,Html,Vue.js,Vuejs2,我有一个非常简单的index.html文件,用于学习Vue。我在一个按钮上附加了一个点击事件,它应该会提醒用户 index.html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Hello Visitor</t

我有一个非常简单的
index.html
文件,用于学习Vue。我在一个按钮上附加了一个点击事件,它应该会提醒用户

index.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Hello Visitor</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" media="screen" href="main.css" />
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

</head>
<body>

    <div class="container">
        <div id="app">
            {{ message }}
        </div>
            <input type="text"> </br> </br>
            <button v-on:click="greet" class="btn btn-primary">Greet Me!</button>   
    </div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script src="main.js"></script>
</body>
</html>

我认为函数需要函数中的
事件
参数,但这没有帮助。是否有我遗漏的内容?

您的Vue应用程序已绑定到
#app

发生在该div之外的东西,Vue不解析也不知道


将您的按钮移动到
#app
div中,它就会正常工作。您可能还想给
一个
type=“button”
——这将阻止它尝试提交表单,这是默认行为。(您也可以执行
来完成相同的操作。
.prevent
阻止默认行为。)

您的Vue应用程序绑定到
#app
。发生在该div之外的东西,Vue不解析也不知道。你的按钮不在你的
el
…哇。我在那里完全失明了。我肯定会添加
type=按钮
。万分感谢!
new Vue({
   el: '#app',
   data: {
       message: 'What is your name?'
    },
    methods: {
       greet: function(){
          alert("Hello to you too.");
       },
    }
});