Comments (12)
This is a module import order issue - because your main.js
depends on other modules, those other modules are evaluated before main.js
. In ES6, all import
statements are hoisted, so even if you import other modules after Vue.use(VueResource)
, they still evaluate before that.
One work around is using require()
instead of import
which is not hoisted; another solution is to have a "bootstrap file" where you install all Vue plugins and export Vue again.
Finally, I think it's probably better to re-design vue-resource
so that it can be imported and used individually without relying on the global Vue.use()
.
from webpack.
@OEvgeny I wouldn't recommend adding Vue
to globals anyway. Calling Vue.use
within each module is the correct way to do this. Glad to hear that it's working for you. 😃
from webpack.
This is working as intended. See the vue-resource docs for example usage.
from webpack.
The reason Vue.resource
does not exist in the module is because it's a module. You're importing a fresh copy of Vue
, because that other copy only exists within main.js. Vue.use(Resource)
in main.js adds vue-resource to the context (this
) of every component included from the App
component.
from webpack.
What if I need to use vue-resource directly from Vue
because I perform some request out of my components? It is supported by vue-resource. I mean you can do it in a way I described abowe, but it's not working correctly with webpack because of modularity.
To work around this I tried to define Vue globally with providePlugin
but is seems to not work too.
from webpack.
In the module that you want to use vue-resource in, is it still not working after Vue.use(Resource)?
from webpack.
It looks like with Vue in globals it's not working too (see ProvidePlugin
config for details). But when I call Vue.use
in each module where I using resource directly it works.
from webpack.
@chrisvfritz I think it is not recommended, because I need to do it for each module where I use it. I moving my project into this boilprate, so before it was working well with webpack.
I also tried to export resource directly from main.js
, and than import it in modules what depends on resource
. It does not work too. Looks like mian module evaluates after another ones what need it because I found resource to be undefined.
from webpack.
@yyx990803 sorry for mention you, but I think it can be important
I created a repo with my issue:
vue init OEvgeny/webpack test
cd test
npm i
npm run dev
Than follow console log in localhost:8080. My output:
There is no resource: undefined
Resource is defined and exported: function Resource () {...}
Api is not defined undefined
from webpack.
@yyx990803 Thanks for explanation Evan!
from webpack.
@yyx990803 Thanks!
from webpack.
@TheDeveloperTom you should definitely check out Evans post about retiring vue-resource https://medium.com/the-vue-point/retiring-vue-resource-871a82880af4
from webpack.
Related Issues (20)
- I run this new project,but this show nothing in IE 11,can you solve the problem?
- r 403 forbidden
- Actually, you could overwrite `publicPath` in `ExtractTextPlugin` as you want. HOT 1
- HMR with express server with NodeJS API
- When load image via binding attribute, scss error occure.
- The vue project is configured with babel-polyfill but still displays a blank page in ie
- Updated Webpack 2 to 4 and faced issues while building for production
- webpack test fails because of import export error!!!
- Vuetify : "Expected newline." loading vuetify sass files HOT 1
- Laravel Vue templates won't update on shared hosting!
- npm err unexpected end of json input while parsing near '... RE----\r\n"}},"1.2.0' HOT 1
- how i solve this HOT 2
- Build error related to "@import" of styles HOT 1
- Can`t use prod.env.js variable in proxy config
- Error: Can't resolve '@fontawesone/fontawesone-free/css/all.css' in 'D:\xamppp\htdocs\laravel\laravel\VeuDemo\login1\login1\src\plugins'
- set default assetsPublicPath to './' instead of '/'
- npm ERR! Unexpected end of JSON input while parsing near '.../registry.npmjs.org/v'
- Using VueJs in .Net MVC. everything compiles fine but i am getting an empty view
- > > I run this is the console of my navigator (Chrome), and no error message anymore :
- how to fix npm run build blank display with vue-cli 3.2.45
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webpack.