Struggling to find any pre-made examples of use for the vue-resource plugin of vue.js, I tried this :
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/0.12.7/vue.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue-resource/0.1.13/vue-resource.min.js"></script>
<div id="my_view">
  <p>{{ origin }}</p>
</div>
<script>
var Vue = require('vue');
Vue.use(require('vue-resource'));
new Vue({
    el: '#my_view',
    data: {
       origin: ''
    },
    ready: function() {
        // GET request
        this.$http.get('http://httpbin.org/ip', function (data, status, request) {
            // set data on vm
            this.$set('origin', data)
        }).error(function (data, status, request) {
            // handle error
        })
      }
})
</script>
to just query httpbin.org/ip (a random REST endpoint i could find) and display the result inside #myview > p. It's just the example (an adapted version) provided on the vue-resource github page that I'm trying to run.
Can anyone see what I'm not getting right to achieve this ?
Edit: added comma, and here is the fiddle of it.
Its because you are using require. If you use require you need some lib like http://browserify.org/
This example is now working: http://jsfiddle.net/dccbbkam/2/
And here is another example for you: http://jsfiddle.net/dccbbkam/4/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With