小编mad*_*raw的帖子

未捕获(承诺中)类型错误:X 不是函数

我正在尝试构建一个 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)

javascript api vue.js

3
推荐指数
1
解决办法
6278
查看次数

标签 统计

api ×1

javascript ×1

vue.js ×1