我正在尝试连接Vue.js代码与超文本标记语言页面,以呈现一些数据。我不知道如何连接,我给了下面的代码,我已经尝试过。
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.12/dist/vue.js"></script>
<script src='./vue.js'></script>
<body>
<div id="app">
<h1>{{ message }}</h1>
</div>
</body>
</html>Vue.js:
var myObject = new Vue({
el: '#app',
data: {message: 'Hello Vue!'}
})发布于 2021-02-02 17:42:41
您应该将vue.js脚本移动到body部分as described in the Vue.js tutorial you are doing的末尾。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.12/dist/vue.js"></script>
<body>
<div id="app">
<h1>{{ message }}</h1>
</div>
<script src='./vue.js'></script>
</body>
</html>有关放置脚本标记的位置的更多信息:When to use the tag in the head and body section of a html page?
发布于 2021-02-02 18:51:38
您也可以保留原样,并从以下位置进行更改:
<script src='./vue.js'></script>至
<script defer src='./vue.js'></script>https://stackoverflow.com/questions/66006964
复制相似问题