Wednesday, 4 July 2018

Vue.js Get Json Data and Display

Index.html
<html>
<title></title>
    <head>
        <!-- Import Vue library -->
        <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    </head>
    <body>
        <div id="app">
            <li v-for="msg in json">
                {{msg}}
            </li>
            <input v-model="text"/>
            <button @click="DisplayData">Query</button>
        </div>
    <script src="index.js"></script>
    </body>
</html>


Index.js
var app = new Vue({
    el: "#app",
    data: {
        text: "",
        json: null
    },
    methods: {
        DisplayData: function () {
            if (this.text)
            {
                fetch("https://api.github.com/users/" + this.text)
                    .then(r => r.json())
                    .then(json => { this.json = json; });
            }
        }
    }
});


No comments:

SQL: Generate a range of numbers

SELECT ones.n + 10*tens.n + 100*hundreds.n + 1000*thousands.n FROM       (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) ones(n),      (VALU...