0

I known how to get value from input element.

<div id="app-6">
<p>{{ url }}</p>
<input v-model="url">
</div>
<script>
new Vue({
    el: '#app-6',
    data: {
        url: ''
    }
})
</script>

And I want to use url variable to get page like this:

<div id="app-6">
    <input v-model="url">
    <input type="submit" v-on:click="open">
    <p>{{ result }}</p>
</div>
<script>
new Vue({
    el: '#app-6',
    data: {
        url: '',
        result: ''
    },

    methods : {
        open: function (data) {
            var url = data.url
            this.$http.get('http://httpbin.org/ip', (data) => {
                this.result = data.origin
            }).error(function (data, status, request) {
                //handler error
            })
        }
    }
})
</script>

But it doesn't work. The url variable is null. In console, it print like this:

Access to XMLHttpRequest at 'file:///D:/serialshow/vuetest.html' from 
origin 'null' has been blocked by CORS policy: Cross origin requests 
are only supported for protocol schemes: http, data, chrome, chrome- 
extension, https.

Vue version: 2.5.17

eye_water
  • 107
  • 1
  • 7

1 Answers1

3
  1. You are not sending data to open method, but I suggest to use this.url to get value inside method

Either use

 open: function () {
        var url = this.url;
  1. Run your application in any local server instead directly from D drive
Niklesh Raut
  • 34,013
  • 16
  • 75
  • 109