Vue.js encountered an error during rendering: "Cannot read the length property of undefined."

I am working on a vuejs component that includes a select box. The first step involves selecting an agent or group, which then reveals the second select option. However, if the user fails to select an option from the first select, I want to hide the second select box. Unfortunately, I encountered an error in my computed property: Error in render: "TypeError: Cannot read property 'length' of undefined"

Here is my template:

  <template>
  <div :class="$style['atribution__container']">
    <select
      item-label="name"
      :label="$t('sidebar.filter.atribution.title')"
      :options="atributionTypes"
      :clear="false"
      :placeholder="placeholder"
      :value="atributionType"
      @input="handleAtributionType"
    ></select>

    <select
      v-if="isAtributionType"
      append-to-body
      item-label="name"
      :clear="false"
      :placeholder="$t('sidebar.filter.atribution.placeholder')"
      :options="attributionsItens"
      :value="selectedAtributionFilter"
      @input="handleAtributionFilterSelection"
    ></select>
  </div>
</template>

And here is my script (data, methods and computed property sections):

data() {
      return {
        atributionType: undefined,
        selectedAtributionFilter: undefined,
        selectedAtributionType: undefined,
        isOpen: false,
        atributionTypeDropDownOpen: false,
        ele: []
      }
    },
    computed: {
      ...mapGetters([
        'temporaryFilter',
        'selectedFilter',
        'agents',
        'agent',
        'visibleGroups',
        'hasBots',
        'temporarySelectedFilterName',
        'currentInbox'
      ]),
      placeholder() {
        return this.$te(this.temporarySelectedFilterName)
          ? this.$t(this.temporarySelectedFilterName)
          : this.temporarySelectedFilterName
      },
      atributionTypes() {
        const types = []
        if (this.showAgentFilter) {
          types.push({ name: 'Agente', type: 'agent' })
        }
        if (this.visibleGroups && this.visibleGroups.length) {
          types.push({ name: 'Grupo', type: 'group' })
        }
        return types
      },

     isAtributionType() {
            return !!this.atributionType.length < 0
        }
},
 watch: {
      selectedAtributionIdFilter(id) {
        if (!id) {
          this.atributionType = []

          this.selectedAtributionFilter = []
        }
      },
      atributionType(value) {
        if (!value) {
          this.atributionType = []
          this.selectedAtributionFilter = []
        }
      }
    },

Answer №1

Explore the concept of assigning an empty array to a type

data() {
  return {
    type: [],
    selectedFilter: null, // If you are unsure of the initial purpose,
    selectedType: null, // you can start by setting it as null.
    isOpen: false,
    dropDownOpen: false,
    elements: []
  }
}

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

Ways to determine if your code is written in ES6

After completing a lot of Javascript coding, I just learned about the existence of various JS 'versions' such as ES5 and ES6. My project is now up on Github, and someone advised me to convert my ES6 code to ES5 using Babel. The problem is, I&ap ...

Trap mistakes while utilizing async/await

Within my Express application, I have a register function for creating new users. This function involves creating the user in Auth0, sending an email, and responding to the client. I am looking to handle errors from Auth0 or Postmark individually and send ...

A guide to efficiently eliminating UI elements with React JS

Struggling to find clear instructions on removing UI components in React? Take a common scenario: there's a login form that should disappear after the user submits it. How can this be achieved? Although unmountComponentAtNode exists, it seems like it ...

Switch to a new section element every 20 seconds

After conducting research, I discovered that my initial approach to this task is not feasible. I have two elements on a page: a graph created using the chart.js framework and a data table. The data in the chart only changes once a day, and the data retriev ...

Obtain the input elements and attach a click event to them

I have a form utilizing Bootstrap with three elements. When the button is clicked, another line with three elements is dynamically added. <div class="row align-items-center mb-2 mt-2 ms-1 "> <div class="col-5 ps-1 pe-1"> ...

Developing a downloadable PDF version of an online platform

For weeks now, I have been tirelessly searching for a solution to a problem that has stumped me once before. The Challenge: My company created a sophisticated web-based data analytics suite for a major beverage distributor. Our client is now requesting a ...

Restrict the amount of items fetched when processing JSON information

Here is a snippet of JSON data that I am parsing using JavaScript. "credits":{ "cast":[{ "id":819,"name":"Edward Norton","character":"The Narrator","order":0,"cast_id":4,"profile_path":"/iUiePUAQKN4GY6jorH9m23cbVli.jpg" }, {"id":287,"name": ...

The SimpleHTTPServer is causing Google Maps Places Autocomplete feature to malfunction

Currently, I am implementing a location search feature along with form auto-fill using the google.maps.places.Autocomplete functionality. While accessing the HTML file directly (file:///location.html), everything is functioning as expected. However, when ...

What is the method to check for the absence of an anchor element in jest and react-testing-library?

In my React component, a link is rendered based on a specific rule. The markup looks like this when there is a link within the h4 element: <h4><a href="">foo</a></h4> <p>blah blah <a href="">bar</ ...

The animation in TailwindCss gets disrupted by TinyMce when it is loaded within a slide-over component

I am working on a Vue3 application that heavily utilizes TailwindUI components, and I have successfully placed a TinyMce editor inside a slide over component. The problem arises with the entry animation. Initially, when the slide over opens, it slides in ...

The V-model fails to reflect changes when the checkbox list is updated

I am facing an issue with my checkboxes that are generated dynamically in a component using a v-for loop. Once a checkbox is checked, it is added to an array of selected checkboxes. The problem arises when a checked checkbox is removed - the v-model still ...

Fixing issue of Rails AJAX causing partials to be overwritten upon page refresh

While trying to implement a user show view with dynamic post creation, I encountered an issue when refreshing the page after successfully creating posts. The issue arises when the previously created posts are overwritten with null IDs. Additionally, I am u ...

Guide on adding JSON data from a web service whenever a function is invoked in AngularJS

I am currently calling the getData function every second and everything is working fine except for the appending functionality. Whenever the function is called, AngularJS replaces the old data with new data, but I actually want to append the new data aft ...

Tips for managing submitted data to a server in express?

In the process of sending a post request from my index.js to app.js upon a click event, I have the following code snippet: var data = { name: "Sarah", age: "21" }; var xhr = new XMLHttpRequest(); xhr.open("POST", "/", true); xhr.setRequestHe ...

The identification number is not used to update Mongo DB

When attempting to use the MongoDB driver in Node.js to update a document, I encountered an issue where the log indicated that the update was successful, but the data did not reflect the changes. Specifically, despite trying to update the document using it ...

Conducting various calculations and showcasing them all on a single webpage

Uncertain about what to name this, but let's see if you understand my question. I have a table on a standard HTML page and I am performing some calculations using Javascript/jQuery. Example: function addThem() { var result; result = userIn ...

An unhandled error occurred when trying to call _this3.setState - it seems like _this3 is not a

I encountered an error when trying to set the data in state in reactjs. Here's the scenario: I am passing data from a child component to a parent component. In the child component, I call the parent function and change the state value using setState. ...

Is it possible to update the total price on Shopify using CartJS and JavaScript?

Struggling to get my data updated using AJAX on my Shopify theme, and incorporating the CartJS plugin. The counter is working correctly, but there seems to be an issue with formatting the price. It does calculate the correct total, but fails to display the ...

Tips for using JavaScript to style an array items individually

I have currently placed the entire array within a single div, but I would like to be able to display each element of the array separately so that I can style "date", "title", and "text" individually. This is my JSON structure: [ { "date": "Example ...

Disable the height property in the DOM when implementing the jQueryUI resizable feature

I'm utilizing the flex property to create a responsive layout for my web application. In order to enable resizing of my navigator panel, I have implemented jQuery UI. However, upon triggering the resize event, jQuery UI is adding a hardcoded height t ...