Sveltejs github API

问题描述

<script>
    const urlParams = new URLSearchParams(window.location.search);
    const username= urlParams.get('usrname');
    const repo= urlParams.get('repo');
    const headers = new Headers({'Authorization': 'Basic ' + btoa('usr:pass')})

    export let stars,issues,watchers,forks,repo_name,repo_owner;

    export function exec(event) {

        let data = `${username}/${repo}`;

        event.preventDefault()

        if (data != "") {

            let url = `https://api.github.com/repos/${data}`;
            fetch(url,headers).then(response => response.json()).then(data => {data.stargazers_count = stars,data.watchers_count = watchers,data.forks_count = forks,data.open_issues_count = issues,data.name = repo_name,data.owner.login = repo_owner});
        }
    }
</script>

<head>
    <Meta charset="">
    <Meta name="viewport" content="width=,initial-scale=">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css" integrity="sha512-+4zCK9k+qNFUR5X+cKL9EIR+ZOhtIloNl9GIKS57V1MyNsYpYcUrUeQc9vNfzsWfV28IaLL3i96P9sdNyeRSSA==" crossorigin="anonymous" />
    <title>Listing</title>
</head>

<body>

    <div class="stat-container">
        <div class="stars">
            <i class="far fa-star"></i> <span class="text-stars">{ stars }</span>
        </div>
        <div class="forks">
            <i class="fas fa-code-branch"></i> <span class="text-forks">{ forks }</span>
        </div>
        <div class="watchers">
            <i class="far fa-eye"></i> <span class="text-watchers">{ watchers }</span>
        </div>
        <div class="issues">
            <i class="fas fa-exclamation"></i> <span class="text-stars">{ issues }</span>
        </div>
    </div>

    </body>

    <style>
    </style>

当我传递查询字符串时说undefined是行不通的。对不起,我刚刚开始学习,可能太愚蠢了。 ???

垃圾箱网址(如果要语法突出显示):https://hastebin.com/oxogazobif.xml

示例屏幕截图:

screenshot of page and console errors

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)