有人能解释一下为什么如何破坏模板的呈现吗?关于如何解决这个问题,我已经看到了其他的答案,但是没有一个人详细地解释了为什么它会崩溃。
我运行npm init和npm install vue,而不是使用CLI。
我创建了一个index.html文件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title></title>
<script type="text/javascript" src="node_modules/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<first-task></first-task>
{{msg}}
</div>
<script src="app.js"></script>
</body>
</html>和一个app.js看起来像:
import Vue from 'vue/dist/vue.js'; //Remove to fix
Vue.component('first-task', {
template: '<p>Hello World!</p>'
});
var app = new Vue({
el: '#app',
data: {
msg: "Hello World"
}
});移除导入,它会呈现出很好的效果,但我不清楚为什么会发生这种情况。我唯一的猜测是,默认的new Vue没有引用完整的构建,或者隐式呈现()没有被调用,但是我不知道如何更多地研究这个问题。
发布于 2019-11-24 01:09:11
import语句只能出现在javascript模块中。
<script type="module" src="app.js"></script>应该修复它,尽管您已经看到,无论如何都不需要用当前代码导入Vue。
https://stackoverflow.com/questions/59013320
复制相似问题