Cannot read property '$vm' of undefined
See original GitHub issuecode like these:
const Vue = require('vue');
const VueRouter = require('vue-router');
const App = require('./app.vue');
Vue.use(VueRouter);
Vue.use(VueResource);
let app = Vue.extend(App);
Vue.http.post( '/url').then((res)=> {}, (err)=> {});
the webpack loader config like this:
loaders: [
{
test: /\.vue$/, loader: 'vue-loader'
},
{
test: /\.js$/, loader: 'babel-loader'
}
]
babel config:
{ "presets": ["es2015","stage-2"] }
and then the error:** Uncaught TypeError: Cannot read property ‘$vm’ of undefined**
error code part:
function Http(url, options) {
var client = Client,
request,
promise;
Http.interceptors.forEach(function (handler) {
client = interceptor(handler, this.$vm)(client);
}, this);
options = _.isObject(url) ? url : _.extend({ url: url }, options);
request = _.merge({}, Http.options, this.$options, options);
promise = client(request).bind(this.$vm).then(function (response) {
return response.ok ? response : Promise.reject(response);
}, function (response) {
if (response instanceof Error) {
_.error(response);
}
return Promise.reject(response);
});
if (request.success) {
promise.success(request.success);
}
if (request.error) {
promise.error(request.error);
}
return promise;
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Vue unit tests - cannot read property 't' of undefined
I'm using jest to run vue unit tests to check the output of individual components. The component uses vuetify. I create an instance...
Read more >Wrapper | Vue Test Utils
Properties. # vm. Component (read-only): This is the Vue instance. You can access all the instance methods and properties of a vm with...
Read more >[vue warn]: error in render: "typeerror: cannot read properties ...
The problem is caused by duplicated loading of vue.js. Your code only loads the standalone build of vue.js ( import Vue from vue/dist/vue.js)...
Read more >Vue warn]: Error in render: "TypeError: Cannot read property ...
Coding example for the question [Vue warn]: Error in render: "TypeError: Cannot read property '"' of undefined"-Vue.js.
Read more >Vue-resource: cannot read property '$http' of undefined
I've tried called $http as 'this.$http', and the same thing happens. I know that I don't fully understand what governs the usage of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Bable with
es2015
presets addsuse strict mode
which causes this issue. Can you try v0.7.4 which will work in strict mode as it supposed to.@leaves4j See this issue, it can resolve the problem.