Vue 未定义,即使它已被导入
Vue not defined even though it's been imported
所以我已经使用 npm 安装了 vuejs:
"dependencies": {
"vue": "^2.5.2"
}
而且我也将其导入到我的文件中:
import "vue"
const app = new Vue({
el: "#app",
template: `
<div>
<h1>Siddharth Knows It All</h1>
</div>
`
});
但我面临的问题是,当我使用 webpack 编译代码并在本地服务器上 运行 时,在控制台中输出 Vue is not defined
.
控制台也输出
You are running Vue in development mode. Make sure to turn on
production mode when deploying for production. See more tips at
https://vuejs.org/guide/deployment.html
谁能帮帮我?
据我所知,你应该使用:
import Vue from 'vue';
花点时间阅读一下 import
语句的实际工作原理可能是值得的。
你所做的本质上是导入模块只是为了它的副作用:
Import a module for its side effects only
Import an entire module for side effects only, without importing
anything. This runs the module's global code, but doesn't actually
import any values.
import '/modules/my-module.js';
您要做的是导入模块的默认 export
:
Importing defaults
It is possible to have a default export (whether it is an object, a
function, a class, etc.). The import statement may then be used to
import such defaults.
import myDefault from '/modules/my-module.js';
所以我已经使用 npm 安装了 vuejs:
"dependencies": {
"vue": "^2.5.2"
}
而且我也将其导入到我的文件中:
import "vue"
const app = new Vue({
el: "#app",
template: `
<div>
<h1>Siddharth Knows It All</h1>
</div>
`
});
但我面临的问题是,当我使用 webpack 编译代码并在本地服务器上 运行 时,在控制台中输出 Vue is not defined
.
控制台也输出
You are running Vue in development mode. Make sure to turn on production mode when deploying for production. See more tips at https://vuejs.org/guide/deployment.html
谁能帮帮我?
据我所知,你应该使用:
import Vue from 'vue';
花点时间阅读一下 import
语句的实际工作原理可能是值得的。
你所做的本质上是导入模块只是为了它的副作用:
Import a module for its side effects only
Import an entire module for side effects only, without importing anything. This runs the module's global code, but doesn't actually import any values.
import '/modules/my-module.js';
您要做的是导入模块的默认 export
:
Importing defaults
It is possible to have a default export (whether it is an object, a function, a class, etc.). The import statement may then be used to import such defaults.
import myDefault from '/modules/my-module.js';