Vue Axios非同期要求

17668 ワード

データ#データ#
{
  "name": "shouhe",
  "age": 18,
  "isBoy": true,
  "house": {
    "location": "zhejiang",
    "port": 8080,
    "num": [0,1,2,3]
  }
}

完全な書き方:

<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Titletitle>
head>
<body>
<div id="app">
    <h3>{{info}}h3>
    <h3>{{info.name}}h3>
    <h3>{{info.age}}h3>
div>
<script src="https://lib.baomitu.com/vue/2.6.11/vue.min.js">script>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.19.2/axios.js">script>
<script>
    var vm = new Vue({
        el: "#app",
        data() {
            return {
                info: {
                    name: null,
                    isBoy: null,
                    age: null,
                    house: {
                        location: null,
                        port: null,
                        num: null
                    }

                }
            }
        },
        mounted() {
            axios.get('data.json').then(response => (this.info = response.data));
        }
    });
script>
body>
html>

簡単な書き方:

<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Titletitle>
head>
<body>
<div id="app">
    <h3>{{info}}h3>
    <h3>{{info.name}}h3>
    <h3>{{info.age}}h3>
div>
<script src="https://lib.baomitu.com/vue/2.6.11/vue.min.js">script>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.19.2/axios.js">script>
<script>
    var vm = new Vue({
        el: "#app",
        data() {
            return {
                info: {}
                }
            }
        },
        mounted() {
            axios.get('data.json').then(response => (this.info = response.data));
        }
    });
script>
body>
html>