我正在嘗試使用此功能(src/api/)
function getChampionName(champId) {
axios.get('http://ddragon.leagueoflegends.com/cdn/12.5.1/data/en_US/champion.json')
.then(({ data }) => {
let list = data
let championList = list.data
for (var i in championList) {
if (championList[i].key == champId) {
return championList[i].id
}
}
})
.catch((err) => console.log(err))
}
export {getChampionName}
在這個組件中(src/components/)
<template>
<div class="w-72">
<header class="rounded-tl-lg rounded-tr-lg bg-slate-400 p-0.5">
<p>Champion's Mastery</p>
</header>
<ul class="grid gap-1 rounded-bl-lg rounded-br-lg bg-slate-50 p-0.5">
<li v-for="champ in masteryData.slice(0,10)" :key="champ.championId">
<div class="flex items-center justify-between">
<div class="flex items-center gap-2">
<img src="https://ddragon.leagueoflegends.com/cdn/12.5.1/img/champion/Karma.png" alt="" class="rounded-lg h-14 w-14">
<div>
<p class="font-medium text-center">{{ getChampionName(champ.championId) }}</p>
<p>Level {{ champ.championLevel }}</p>
</div>
</div>
<p class="text-2xl font-medium">{{ champ.championPoints }} Pts</p>
</div>
</li>
</ul>
</div>
</template>
<script>
import getChampionName from '@/api/search'
export default{
name: 'MasteryInfo',
props: [
'masteryData'
],
methods: {
getChampionName
}
}
</script>
但是我收到了這個錯誤Method "getChampionName" has type "undefined" in the component definition.,不知道這是什么意思。
uj5u.com熱心網友回復:
看來您沒有正確匯入該方法。將匯入更改為:
import { getChampionName } from '@/api/search';
您可以在此處閱讀有關 javascript 中匯入匯出的更多資訊: https ://javascript.info/import-export
如果你覺得和這個問題差不多,也可以參考這個: Method "showDate" has type "undefined" in the component definition
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/442211.html
