码迷,mamicode.com
首页 > 移动开发 > 详细

【Vue】axios异步通信

时间:2020-12-15 12:22:45      阅读:4      评论:0      收藏:0      [点我收藏+]

标签:问题   ios   try   net   子函数   return   ret   highlight   address   

 

data.json

{
  "name": "java",
  "url": "http://www.baidu.com",
  "page": 1,
  "isNonProfit": true,
  "address": {
    "street": "凯宾路",
    "city": "上海",
    "country": "中国"
  },
  "links": [
    {
      "name": "bilibili",
      "url": "https:www.bilibili.com"
    },
    {
      "name": "java",
      "url": "https:www.java.com"
    },
    {
      "name": "百度",
      "url": "https:www.baidu.com"
    }
  ]
}
  

  

<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        /*解决闪烁问题*/
        [v-clock]{
            display: none;
        }
    </style>
</head>
<body>
<div id="app" v-clock>
    <div>{{info.name}}</div>
    <a  v-bind:href="info.url">超链接</a>
    <div>{{info.page}}</div>
    <div>{{info.isNonProfit}}</div>
    <hr>
    <div>{{info.address.street}}</div>
    <div>{{info.address.city}}</div>
    <div>{{info.address.country}}</div>
    <hr>
    <div  v-for="link in info.links">{{link.name}}</div>

</div>

<script src="https://cdn.jsdelivr.net/npm/vue@2.5.21/dist/vue.min.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script type="text/javascript">
    var vm = new Vue({
        el: "#app",
        data(){
            return{
                info:{
                    name:null,
                    url:null,
                    page:null,
                    isNonProfit:null,
                    address:{
                        street:null,
                        city:null,
                        country:null
                    },
                    links:[
                        {
                            name:null,
                            url:null
                        }
                    ]

                }
            }
        },
        mounted(){//钩子函数
            axios.get(‘../data.json‘).then(response=>(this.info=response.data));
        }
    });

</script>
</body>
</html>

  

 

【Vue】axios异步通信

标签:问题   ios   try   net   子函数   return   ret   highlight   address   

原文地址:https://www.cnblogs.com/ixtao/p/14110747.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!