Javascript 导入Vue将中断Vue
有人能解释一下为什么Javascript 导入Vue将中断Vue,javascript,vue.js,Javascript,Vue.js,有人能解释一下为什么从“Vue”导入Vue会破坏模板的呈现吗?我已经看到了关于如何解决这个问题的其他答案,但没有一个详细说明它为什么会破裂 我运行了npm init和npm install vue,没有使用CLI 我创建了一个index.html文件: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" con
从“Vue”导入Vue
会破坏模板的呈现吗?我已经看到了关于如何解决这个问题的其他答案,但没有一个详细说明它为什么会破裂
我运行了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>
删除导入后,效果会很好,但我不清楚为什么会发生这种情况。我唯一的猜测是默认的
新Vue
没有引用完整版本,或者隐式Render()没有被调用,但我不确定如何进一步研究这个问题。import
语句可能只出现在javascript模块中
应该修复它,但正如您所看到的,您不需要使用当前代码导入Vue
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"
}
});
<script type="module" src="app.js"></script>