我正在尝试构建一个 vue 应用程序,通过 Spotify 的 API 进行搜索来查找曲目。但我有一个问题,它说:
未捕获(承诺中)TypeError:searchTracks 不是函数
每当我调用 searchTracks 函数时。我寻找解决方案,但似乎找不到。我有在不同文件 (useSpotify.js) 上访问 Spotify API 的代码(我仍在学习)
import { ref } from 'vue'
const useSpotify = async () => {
let token
const id = 'MyId'
const secretId = 'mySecretId'
const res = await fetch('https://accounts.spotify.com/api/token', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic ' + btoa(id + ':' + secretId)
},
body: 'grant_type=client_credentials'
});
token = await res.json();
console.log(token);
const searchTracks = async (searchTerm) => {
console.log(token)
const res …Run Code Online (Sandbox Code Playgroud)