简体   繁体   English

在webpack和Vuejs中包含其他js

[英]Include other js in webpack vs Vuejs

I want to inject a script file to web pack but when run i have a error Uncaught ReferenceError: Vue is not defined HOw i can do it In Main.js 我想将脚本文件注入Web Pack,但运行时出现错误Uncaught ReferenceError:未定义Vue如何在Main.js中做到这一点

import Vue from 'vue';
import nqt from './nqt.js';
//Vue.use(nqt)

In nqt.js 在nqt.js中

vm = new Vue();
console.log(vm);

Thank for read! 感谢您的阅读!

You are using es6 modules in your project. 您在项目中使用es6模块。 And to use any module inside another modules you need to first import it. 要在另一个模块中使用任何模块,您需要先将其导入。

Add this line on top of your ./nqt.js 将此行添加到您的./nqt.js顶部

import Vue from 'vue';

Now if you want the vm defined in ./nqt.js to be used inside other modules, you need to export it here like this. 现在,如果要在./nqt.js定义的vm在其他模块中使用,则需要将其导出到此处。 var vm = new Vue(); var vm = new Vue(); export default vm; 导出默认的vm;

And then import it inside ./main.js 然后将其导入./main.js

import vm from `./nqt.js`

In order to get how it works take a look at http://2ality.com/2014/09/es6-modules-final.html 为了了解其工作原理,请访问http://2ality.com/2014/09/es6-modules-final.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM