Vuejs search functionality not working when using the filter method

I'm relatively new to Vue.js and I'm attempting to utilize the computed method in order to create a search bar that specifically searches through names. However, I keep encountering an error stating "'this.info.filter' is not a function."

<template>
<div class="container">
  <input type="text" v-model="search" placeholder="Search by name">
   <div class="content" v-for="student in filterName " v-bind:key="student.id">
      <img class="image" :src="student.pic" alt="">
      <div class="student-info">
          <h1 class="info">{{student.firstName +" "+ student.lastName}}</h1>
          <div class="infomation">
            <p class="cop">{{ student.company }}</p>
            <p class="ski">{{ student.skill }}</p>
            <p class="email">{{ student.email }}</p>
            <p class="grade">{{ student.grades }}</p>
          </div>
      </div>
  </div>
</div>
</template>

<script>

import axios from "axios";
export default {
  name: "Student.vue",
  data() {
    return {
      students: '',
      search: ''
    }
  },
  mounted() {
    axios
        .get('https://api.hatchways.io/assessment/students')
        .then((res) => {
          this.students = (res.data.students)
        })
  },
  computed :{
    filterName:function (){
      return this.info.filter((student)=>{
        return student.company.matcth(this.search);
      })
    }
  }
}
</script>

</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

This is my first time using StackOverflow as well, so please disregard any errors.

Answer №1

In your code, it appears that this.info has not been declared or initialized.

The error you're encountering is due to the fact that the filter function is attempting to operate on a variable that is undefined (this.info is currently set to undefined).

To resolve this issue, you may consider initializing this.info as an empty array within the data section.

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

Encountered difficulties while attempting to set up React.js

Why am I encountering difficulties installing React? I managed to create a node module file, but it is being automatically deleted. I ran the command npx create-react-app my-app. Below is a screenshot. Aborting installation. npm install --no-audit --save ...

How can you loop through keys and values in a JSON object using JavaScript?

I am attempting to cycle through the JSON data below: { "VERSION" : "2006-10-27.a", "JOBNAME" : "EXEC_", "JOBHOST" : "Test", "LSFQUEUE" : "45", "LSFLIMIT" : "2006-10-27", "NEWUSER" : "3", "NEWGROUP" : "2", "NEWMODUS" : "640" } The keys in this JSON are d ...

Adding some characters before a specific character within a string variable in JavaScript

Seeking a solution for transforming the contents of a JavaScript variable. var data = "ashley, andy, juana" The desired output is as follows: var data = "Sports_ashley, Sports_andy, Sports_juana" We need this transformation to be dynamic and able to ha ...

Listen for incoming data from the client in the form of an ArrayBuffer

I have been utilizing the ws library within nodejs to develop a small cursor lobby where players can interact. I have managed to utilize the server to send ArrayBuffers with bit streams to the client and successfully decode them. However, I am encountering ...

Troubleshooting Automatic Scrolling Problems in React Virtualized

In my project utilizing react-virtualized v-9.21.2 to showcase a list, a problem arises when adding a new item. I employ a method of clearing the cache and updating the listKey to enable auto resizing the height. However, this results in an undesired behav ...

What are the best ways to conceptualize the benefits of WebRTC?

I encountered a peculiar issue with the abstraction of the WebRTC offer generation process. It appears that the incoming ice candidates fail to reach the null candidate. While I have been able to generate offers successfully using similar code in the past, ...

Retrieve all data with the same attribute name in one statement from the ajax call

After making an Ajax call, I receive the following data, which includes two images but the number of images can vary: [{"BadgeImage":"http:\/\/localhost:8666\/web1\/profile\/images\/badge image 2\/1.png"}, {"BadgeImag ...

Using JavaScript to extract the metadata of an image from a remote location

Is there a way to extract XMP metadata from a JPEG file using JavaScript? I came across a method for doing it in PHP (How can I read XMP data from a JPG with PHP?) which can be adapted for JavaScript using AJAX. However, the issue arises when trying to acc ...

What are the benefits of using one state in React with useState compared to having multiple states?

Is it more beneficial to optimize and enhance code readability in React using Hooks and Functional components by utilizing a single setState hook or having multiple hooks per component? To further elaborate, let's consider the following: When workin ...

Blend the power of Node's CommonJS with the versatility of Typescript's ES modules

I currently have a Node.js v10 legacy application that was built using CommonJS modules (require). The entire codebase is written in JavaScript. However, I am considering upgrading the app and refactoring a specific part of it to use TypeScript modules ( ...

How to access the ID value from the URL within a different component that was passed as a prop in

I have a scenario where I am building a reusable component with two child components in the following flow: Child Component 1 -> Parent Component -> Super Parent Main Component In the child component, I define a prop called 'url' which is ...

Hide the button with jQuery Ajax if the variable is deemed acceptable upon submission

I need to figure out how to hide the submit button if the email entered is the same as the one in the database from action.php. Can anyone help me with integrating this functionality into my existing code? <form onsubmit="return submitdata();"> ...

What is the best way to incorporate a Bootstrap modal for delete confirmation before proceeding with data deletion through a POST request?

As a beginner in web development, I am currently learning how to use JavaScript, Express, Node, and Mongoose. In my app, I want to display a confirmation modal using Bootstrap before deleting any data, only proceeding with the deletion when the user clicks ...

Testing the Angular/Ionic project through unit tests

I am facing a challenge with my controller code, which appears to be quite simple. Here is a snippet of the controller: timeInOut.controller('timeInOutController', function($scope, $filter, $ionicScrollDelegate){ ... }); However, when at ...

Utilize Mapbox-GL.JS to animate several points along designated routes

I'm encountering issues with the following example: Animate a point along a route My goal is to add another point and routes in the same map container. Here's what I've tried so far: mapboxgl.accessToken = 'pk.eyJ1IjoicGFwYWJ1Y2t ...

What prevents me from initializing a blank Map or Set using Object.create?

Unfortunately, the code snippet provided is not functioning as expected. Here's what I attempted: const x = Object.create(Set.prototype) x.has(1) const y = Object.create(Map.prototype) y.get(1) I wanted a method to generate empty objects rega ...

What causes AngularJS to generate an error when attempting to construct a URL for the src attribute of an iframe?

Recently, I've been working with AngularJS directives and encountered an issue while trying to use an expression in the src attribute of an iframe. The error message I received referenced a URL that didn't provide much insight: http://errors.ang ...

Vue has detected that the property or method "index" is being referenced in the render function, but it is not defined on the instance

<div class="input-wrapper" id="name" :data-text="name" :class="{ error: error.isErrorName }"> <input type="text" name="name" placeholder="Name…" @input="inputName($event.target.value)"> </div> data () { retur ...

Accessing variables from an external script in jsdom

Here is a simple example of jsdom code using the script parameter. Despite my best efforts to reference external JS files, I keep running into this issue: ReferenceError: exVar is not defined Does anyone know what might be causing this problem and how ...

Retrieve the content entered in a form text field without needing to officially submit the form

Is it possible to submit the text box value (partnumber) as a query string in a hyperlink without submitting the form itself? I have been trying to achieve this by using document.getElementById("partnumber").value but keep getting an error "Object Required ...