gpt4 book ai didi

javascript - 为什么导入 Vue.js 源有效,但模块无效?

转载 作者:行者123 更新时间:2023-11-30 09:32:51 25 4
gpt4 key购买 nike

以下HTML代码

<!DOCTYPE html>
<html lang="en">
<body>
Greeting below:
<div id="time">
{{greetings}}
</div>
<script src='bundle.js'></script>
</body>
</html>

连同 entry.js文件

// either the import or the require work
Vue = require('./vue.js')
//import Vue from './vue.js'
new Vue({
el: "#time",
data: {
greetings: "hello world"
}
})

webpack.config.js

module.exports = {
entry: './entry.js',
output: {
filename: 'bundle.js'
}
}

工作正常(vue.js 是从站点或 CDN 本地下载的)。

然后我尝试使用 vue通过 npm install vue --save-dev 安装的模块通过更改 entry.js

import Vue from 'vue'
new Vue({
el: "#time",
data: {
greetings: "hello world"
}
})

这个版本不再有效:整个<div>未呈现(仅显示 Greeting below)。

应该怎么做才能让 Vue.js 与 webpack 一起使用?

Vue 文档多次提到 webpack,但只是在组件或生产构建的上下文中。

最佳答案

您可以改为导入 vue 的编译(dist)版本。

从 'vue/dist/vue.js' 导入 Vue

关于javascript - 为什么导入 Vue.js 源有效,但模块无效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45269770/

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