我最近了解vue
我有这个文件main.js
import Vue from 'vue/dist/vue.js'
import Buefy from 'buefy'
import 'buefy/lib/buefy.css'
Vue.use(Buefy)
var App = new Vue({
el: '#app',
data: {
message : "It's working"
}
})
这是我的HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Vue Example</title>
</head>
<body>
<h3 id="app">{{ message }}</h3>
<script src="dist/build.js"></script>
<script>
</script>
</body>
</html>
它正在运作。但是,现在我正在尝试用我的脚本做点什么。我更改main.js
(我正在使用webpack
)
import Vue from 'vue/dist/vue.js'
import Buefy from 'buefy'
import 'buefy/lib/buefy.css'
Vue.use(Buefy)
然后我的index.html到了这个
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Vue Example</title>
</head>
<body>
<h3 id="app">{{ message }}</h3>
<script src="dist/build.js"></script>
<script>
var App = new Vue({
el: '#app',
data: {
message:"It's not working"
}
})
</script>
</body>
</html>
我收到此错误
未捕获的ReferenceError:未定义Vue
我该如何解决这个问题?
答案 0 :(得分:30)
如果您想直接在Vue
制作index.html
的新实例,则应在index.html
中添加该库:
<script src="https://unpkg.com/vue@2.4.2"></script>
或者您需要在Vue
中分配window
到main.js
对象,如下所示:
<强> main.js:强>
import Vue from 'vue';
window.Vue = Vue;
然后在index.html
中您可以访问Vue()
,因为它是window
对象的全局属性。