简体   繁体   中英

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

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

In nqt.js

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

Thank for read!

You are using es6 modules in your project. And to use any module inside another modules you need to first import it.

Add this line on top of your ./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. var vm = new Vue(); export default vm;

And then import it inside ./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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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