2

I'm new to Sails.JS and want to use Vue.JS in my views (every .ejs has a script) but I don't know the correct way to do it. If I create a script tag in the end of the view, this throws an error because Vue.JS hasn't loaded. So, I created a folder in assets to save all my .js files and now I don't know how to import Vue-Resource without getting this error: Cannot read property 'get' of undefined.

I've checked this: https://github.com/pagekit/vue-resource/issues/579 but still haven't had success.

Thanks for your help!

johnabrams7
  • 399
  • 2
  • 10
learango
  • 133
  • 1
  • 7

1 Answers1

1

In your vue main.js make sure you have

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

In vue templates you can access it like:

<script>
    export default {
        data(){
            return {}
        },
        created(){
            console.log(typeof this.$http);
        },
        mounted(){
            console.log(typeof this.$http);
        }
    }
</script>

When dealing with resources I recommend using Vuex and use the state to hold the data. https://vuex.vuejs.org/

Kubwimana Adrien
  • 2,463
  • 2
  • 8
  • 11