我正在尝试将vue-resource与browserify一起使用。但我总是得到以下错误。 Cannot read property 'get' of undefined
。我尝试在网上搜索,但解决方案无效。
var Vue = require('vue');
Vue.use(require('vue-resource'));
import UploadImage from './components/UploadImage.vue'
new Vue({
el: '#app',
components: { UploadImage },
ready() {
console.log('Vue is ready.');
this.$http.get('/api', function(data){
console.log(data);
});
}
});
我使用npm install安装vue
和vue-resource
。
的package.json
{
"private": true,
"devDependencies": {
"clipboard-js": "^0.1.0",
"gulp": "^3.8.8",
"gulp-batch-replace": "0.0.0",
"gulp-phpunit": "^0.14.0",
"laravel-elixir-vueify": "^1.0.3",
"vue": "^1.0.24",
"laravel-elixir-browserify": "^0.8.1",
"vue-resource": "^0.7.0",
"vueify": "^8.4.1"
},
"dependencies": {
"babel-runtime": "^6.0.0",
"bootstrap-sass": "^3.0.0",
"laravel-elixir": "^5.0.0"
}
}
答案 0 :(得分:2)
试试这个:
ready() {
Vue.http.get('/api').then((response) => {
console.log(response.data);
});
}
答案 1 :(得分:0)
以下是我的建议:
1:使用webpack替换browserify。
2:使用axios替换vue-resource。