vue请求开放接口的小demo

根据关键词搜索音乐,采用开放api ajax请求方式

第一步:新建vue文件
新创建页面
第二步:index.js 引入文件路径,路由访问路径
在这里插入图片描述

第三步OneDemo 代码:
<template>
  <div class="one">
    <input type="text" v-model="searchname"><button @click="search">搜索</button>
    <ul>
       <li v-for="(item,i) in shuzu"
          :key="i">
          <img :src=" item.pic">
          <a :href="item.url" target="_blank">{{item.title}}--{{item.author}}</a> 
      </li>
    </ul>
    <br>
    <br>
    <br>
    <br>
  </div>
</template>
<script>
export default {
  name: 'HelloWorld',
  data () {
    return {
      msg: '1212121',
      shuzu:[],
      searchname:''
    }
  },
  mounted:function(){//默认加载 
  },
  methods:{
    skyapi:function(name){
      var that =this;
            this.axios.post('https://api.apiopen.top/searchMusic?name='+name).then(function (response) {
                console.log(response.data.result);
                for(let i=0;i<(response.data.result).length;i++){
                  that.shuzu.push((response.data.result)[i])
                  console.log(response.data.result[i])
                }
              }).catch(function (error) {
                console.log(error);
              });
    },
    search:function(){
      this.shuzu=[];
      this.skyapi(this.searchname)
    }
  }
}
</script>
<style>
a{
  text-decoration: none;
}
li{
   text-align:left;
   list-style-type:none;
}
img{
  width: 100px;
  height: 100px;
  border-radius:50%;
}
</style>

最终效果
在这里插入图片描述
----------------------------仅此作为笔记,毕竟好记性不如烂笔头 ^ _^

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值