让我们的后端获取到的歌单信息,在我们前端VUE框架上显示出来。
前后端分离交互
所以我们前端要发送一个请求src-api-新建文件playlist.js
使用request中封装的import axios from 'axios'
来发送请求
获取地址,进行数据请求。
在我们的文件中引用请求文件
import {
fetchList } from '@/api/playlist'
并且通过他获取歌单列表的信息
export default {
data() {
// 定义数组值
return {
playlist: [],
count: 50
}
},
// 生命周期函数
created() {
this.getList()
},
methods: {
// 获取歌单列表
getList() {
fetchList({
start: this.playlist.length, // 开始长度
count: this.count // 每次长度
}).then((res) => {
console.log(res