gpt4 book ai didi

javascript - 导入Vue破坏Vue

转载 作者:行者123 更新时间:2023-12-02 22:27:38 25 4
gpt4 key购买 nike

有人可以解释为什么Import Vue from 'vue'如何破坏模板的渲染吗?我已经看到了有关如何解决此问题的其他答案,但没有一个答案详细说明了它为何会崩溃。

我运行了 npm initnpm 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 没有引用完整的构建,或者隐式 Render() 没有被调用,但我不确定如何进一步研究这一点。

最佳答案

import 语句只能出现在 javascript 模块

<script type="module" src="app.js"></script>

应该修复它,尽管您不需要使用当前代码导入 Vue ,正如您所看到的

关于javascript - 导入Vue破坏Vue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59013320/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com