如何正确导入Vue.js
How to import Vue.js correctly
我从 Vue.js 开始,我想知道如何正确导入它,以便将它与 Webpack 捆绑在一起。
文档中的所有示例似乎都假定 Vue
对象已经存在。
这是我试过的:
const Vue = require('vue')
还有
const Vue = require('vue').Vue
然后
var app = new Vue({ <options> })
此文件随后与 Webpack 捆绑在一起,并在我的 HTML 索引文件中引用。
但我在浏览器中收到此错误(在这两种情况下):
Uncaught TypeError: Vue is not a constructor
如果你使用 ES6,我认为最好的方法是使用
import Vue from 'vue';
var app = new Vue({ <options> })
我从 Vue.js 开始,我想知道如何正确导入它,以便将它与 Webpack 捆绑在一起。
文档中的所有示例似乎都假定 Vue
对象已经存在。
这是我试过的:
const Vue = require('vue')
还有
const Vue = require('vue').Vue
然后
var app = new Vue({ <options> })
此文件随后与 Webpack 捆绑在一起,并在我的 HTML 索引文件中引用。 但我在浏览器中收到此错误(在这两种情况下):
Uncaught TypeError: Vue is not a constructor
如果你使用 ES6,我认为最好的方法是使用
import Vue from 'vue';
var app = new Vue({ <options> })