The component definition for "getChampionName" is showing a type of "undefined." Are you referencing the function properly?

Recently, I attempted to utilize the following function (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}

In this specific component (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>

However, an error message stating

Method "getChampionName" has type "undefined" in the component definition.
just popped up and I'm uncertain about its significance.

Answer №1

You may be encountering an issue with the method import. Make sure to adjust the import statement as follows:

import { getChampionName } from '@/api/search';

To learn more about import and export in JavaScript, check out this resource: https://javascript.info/import-export

If you believe your question is related to a similar issue, you can also refer to this link for guidance: Method "showDate" has type "undefined" in the component definition

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating various rows within a loop can be achieved by using conditional statements to determine

I am faced with a challenge of handling an array of images, among other properties, and I aim to achieve the following outcome: https://i.sstatic.net/BYajY.png As the images reach the end of the container (which fits 4 images on desktops and adjusts for ...

Error: Unable to extract the 'id' property from 'this.props.Name' because it is undefined in ReactJS

Can you please assist me in resolving this issue? Error: Cannot destructure property 'id' of 'this.props.Name' as it is undefined. src/component/Detail.js file import React, { Component } from 'react'; import { Character } f ...

Unlocking the secrets of extracting props from a functional component using vue-test-utils

When trying to access props with a functional component, I cannot simply use wrapper.props(). What is the alternative method for accessing them? Error: [vue-test-utils]: Calling wrapper.props() on a mounted functional component is not allowed. ...

Problem identified with Vue.js: The Log in screen briefly flashes before redirecting the authenticated user (resulting in a full page refresh)

My routing is functioning properly, utilizing navigation guards to prevent users from accessing the login or register routes once they are signed in. However, when I manually type '/auth/signin' in the address bar, the login screen briefly appear ...

Refreshing Facebook comments does not occur when using FB.XFBML.parse()

My JavaScript photo gallery dynamically loads images from an API onto the page when users click on a thumbnail. I want users to be able to leave Facebook comments on each image, so I've included a Facebook comments element on the page containing the g ...

Are there any notable purposes for using the `.d.ts` file extension beyond just improving code readability?

Within my project, I have a file named shims-vue.d.ts located in the src folder: declare module '*.vue' { import type { DefineComponent } from 'vue' const component: DefineComponent<{}, {}, any> export default component } I ...

The angular plugin (jquery timepicker) is having difficulty detecting alterations

Recently, I started working with Angular and encountered a challenge while working on a small exercise. I was trying to use ng-show based on the timing of the previous row, where the input was through jQuery timepicker. However, my Angular code was having ...

Incremental migration to Next.js within the current React application

I'm on a quest to uncover practical examples demonstrating the process of gradually transitioning an existing React application towards Next.js. Despite delving into all available Next.js documentation on incremental adoption strategies like subpaths, ...

Transferring elements from one array to multiple arrays

I have been working with the basics of JavaScript arrays and here is my code snippet: let arr = ['students', 'exams', [{'sub1':80, 'sub2':60},{'grade_sub1':'A', 'grade_sub2':'B&apos ...

Setting up the Webpack DevServer to manage POST requests in a React JS application

I am currently implementing a payment gateway into my React JS project that utilizes client-side routes. AppRouter.js import React from 'react'; import {BrowserRouter, Route, Switch} from 'react-router-dom'; import {TransitionGroup, C ...

Data within object not recognized by TableCell Material UI element

I am currently facing an issue where the content of an object is not being displayed within the Material UI component TableCell. Interestingly, I have used the same approach with the Title component and it shows the content without any problems. function ...

Creating a list repeater using v-for in Vue.js 2 with computed property

Seeking assistance with adding computed columns to a table (last three columns). Suspecting the issue lies in the computed property not correctly referencing the record. Any simple solutions that I might be overlooking? Appreciate any thoughts or insights! ...

Fluctuating price depending on the selected choice

Hello, I am in the process of updating the price based on the selection made from the options. I am unsure whether to use JavaScript or Ajax for this task and how to go about it. Can someone please guide me? <tr> <td width="160">Price:</td ...

"Quick as a keypress, the pace at which we move

Trying to explain my issue as clearly as possible. I have a Pacman game where the player controls Pacman using the keyboard. Pacman moves a constant unit in each direction and collision detection is based on a predefined map with obstacles marked by "-". ...

The property of the object array type is not defined in another document

Currently, I am in the process of restructuring a JavaScript file that utilizes the THREE.js library to create a truck visualization based on input parameters from a form. Although the code was functioning properly, I aim to enhance it with additional visu ...

The dropdown feature on my theme seems to be malfunctioning on Wordpress

I'm having trouble figuring out what I'm doing wrong. The dropdown navigation works fine with the default Wordpress twentyeleven theme, but when I switch to my custom theme, the dropdown stops appearing. Here is the code I'm using: <div ...

Using VueJS's vue-router to match multiple paths effortlessly

I need assistance with vue-router as I am trying to find a way to match two completely different paths. Can someone suggest if there is an array notation that I can utilize for this purpose? ...

Exploring the power of chaining collection methods and promises in Node.js HTTP requests

My goal is to extract data from a MongoDB database using the find() method, specifically retrieving documents that have a specified "room" value. From there, I aim to identify all unique values within the array of rooms, based on the key "variety". I initi ...

What is the reason that .bin/www is recognized as a JavaScript file even though it does not have the .js extension when utilizing express-generator

Can you explain why .bin/www is recognized as a JavaScript file by express-generator even without the .js extension? Whenever I create a bin/ folder with a www file inside, it's automatically identified as a JavaScript file despite the missing .js ex ...

Once I incorporated Bootstrap into my project, I noticed a noticeable white space between the div elements

Welcome to My Code Playground I was sailing smoothly with my project until I decided to include Bootstrap. Seems like there's something missing in the details, so here I am reaching out. If you spot the issue, please feel free to correct my code. &l ...