Uncaught TypeError: Cannot read property 'get' of undefined in VueJs

前端 未结 5 735
猫巷女王i
猫巷女王i 2020-12-20 07:41

I have following code

JS

var vm = new Vue({
  el: \'#vue-in         


        
相关标签:
5条回答
  • 2020-12-20 08:26

    I fixed this issue of the following mode:

    npm install bootstrap-vue --save
    npm install vue-resource --save
    

    in main.js

    import Vue from './bootstrap'
    import BootstrapVue from 'bootstrap-vue'
    
    Vue.use(BootstrapVue)
    

    create bootstrap.js

    import Vue from 'vue'
    import VueResource from 'vue-resource'
    
    Vue.use(VueResource)
    
    export { Vue }
    

    In App.vue

    this.$http.get('/api/module/all').then(...
    
    0 讨论(0)
  • 2020-12-20 08:39

    In order to use $http you must install the vue-resource middleware first. You can use the following command to install it.

    npm install vue-resource --save
    

    After its installed go to your main.js file and import the vue resource as follows

    import vueResource from 'vue-resource'
    

    Now its imported so we just have to call the use method of Vue to work with this middleware. You can call the use method as follows.

    Vue.use(vueResource)
    
    0 讨论(0)
  • 2020-12-20 08:40

    As you have no plugin for vue-resource your this.$http is undefined. To add Vue-resource on js-fiddle add https://cdn.jsdelivr.net/g/vue@2.0.0-rc.4,vue.resource@1.0.0 to the external scripts section.

    0 讨论(0)
  • 2020-12-20 08:40

    I used another way as of Oct 2019. I first installed using NPM like this

    npm install axios --save
    

    I used this below later and doing this below got rid of the error.

    import  axios  from 'axios';
    
    0 讨论(0)
  • 2020-12-20 08:42

    $http.get is from Vue Resource. Make sure you are pulling that in properly by adding vue-resource to your package.json, install it via npm install and in code:

    var Vue = require('vue');
    
    Vue.use(require('vue-resource'));
    

    To use this in fiddle, you have to add vue-resource cdn link in external resources and use following in code:

    Vue.use(VueResource)
    

    See working demo: https://jsfiddle.net/49gptnad/187/

    0 讨论(0)
提交回复
热议问题