Hi, I'm using http service like following code but it throws an error Cannot read property 'options' of undefined
code:
import Vue from 'vue'; // v1.0.13
import VueResource from 'vue-resource'; // v0.5.1
Vue.use(VueResource);
Vue.http
.get(url)
.then((response) => {
// do something
});
error:
Uncaught TypeError: Cannot read property 'options' of undefined
The error seems to be occurred at https://github.com/vuejs/vue-resource/blob/0.5.1/src%2Fhttp.js#L23
Is it a bug?
Or is there wrong usage in my code?
This issue is fix in v0.6.0
@ktsn If your problem was resolved, then please close out this issue.
Sorry for the late response.
There is another error when I have checked v0.6.0.
The error is not occurred if I use http services from a vm instance.
Uncaught TypeError: Cannot read property '$vm' of undefined
@ktsn Can you provide a jsFiddle that reproduces the problem?
@amirrustam
I could not reproduce the error on jsFiddle...
I looked into about the error and I think it happens when loading vue-resource by Webpack.
The error is thrown at https://github.com/vuejs/vue-resource/blob/master/src/http/index.js#L16
this === undefined at line 16 when I load vue-resource by Webpack.
But if I load it by <script> element, this === window and success to send http request.
I resolved the problem and it is from my webpack configuration.
It works after I fixed to prevent babel-loader to convert scripts in node_modules.
{test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/}
I'm sorry to trouble and confuse you.
I had the same problem when trying to pass vue-resource.js throught babel.
Uncaught TypeError: Cannot read property '$vm' of undefined
@adrianthedev use exclude: /node_modules/ configuration, and it can works.
Most helpful comment
I resolved the problem and it is from my webpack configuration.
It works after I fixed to prevent babel-loader to convert scripts in node_modules.
I'm sorry to trouble and confuse you.