Despite being properly registered, the Vuejs component fails to render

I have a dropdown feature named "MissionPlanner" within a .vue file for a single page component. I've properly registered it in my App.vue file.

App.vue

import MissionPlanner from "./MissionPlanner.vue";

export default {
  name: "app",
  components: {
      ...,
    "mission-planner": MissionPlanner
  }
...
<template>
   <mission-planner/>
</template

Despite registering the component, it does not show up when running the Vue application. The rest of the template renders fine, but the "mission-planner" dropdown is missing. I attempted changing the tags to "MissionPlanner" as well, with no success.

Here's my main.js

new Vue({
  render: h => h(App),
  components: {
    "mission-planner": require("./MissionPlanner.vue")
  } //Tried global registration, without any luck
}).$mount('#app')

Update: Upon reviewing the console, I noticed several errors that are unclear to me:

vue.runtime.esm.js?2b0e:619 [Vue warn]: Property or method "chosen" is not defined on the instance but referenced during render. Ensure this property is reactive, either in the data option or by initializing it for class-based components. More info: https://v2.vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

found in

---> <MissionPlanner> at src/MissionPlanner.vue
       <App> at src/App.vue
         <Root>
warn @ vue.runtime.esm.js?2b0e:619
warnNonPresent @ vue.runtime.esm.js?2b0e:2015
get @ vue.runtime.esm.js?2b0e:2070
eval @ MissionPlanner.vue?93e1:18
...

The initial error message mentions 'reactive properties'. I'm uncertain about the implications of these issues. Provided below are snippets from my MissionPlanner.vue regarding its template and script.

<template>
  <div>
   
    <h1 id="jl">Justice League Mission Planner</h1>

    <ul class="roster">
      <h3>Roster:</h3>
      <li v-for="hero in heroes"
          :key="hero.name">

        <span v-if="hero in chosen-heroes.chosenHeroes">✔  </span>

        <span>{{ hero.name }} </span>
        <span class="edit"
              @click="editHero(hero)">edit</span>
      </li>
      ...
    </ul>
    <chosen-heroes :heroes="heroes" />
  </div>
</template>

<script>
import ChosenHeroes from "./components/ChosenHeroes.vue";

export default {
  components: {
   "chosen-heroes" : ChosenHeroes
  },
  data() {
    return {
      heroes: [
        { name: "Superman" },
        { name: "Batman" },
        { name: "Aquaman" },
        { name: "Wonder Woman" },
        { name: "Green Lantern" },
        { name: "Martian Manhunter" },
        { name: "Flash" }
      ],
      newName: "",
      isEdit: false,
      heroToModify: null
    };
...
</script>

Answer №1

<span v-if="hero in chosen-heroes.chosenHeroes">✔ &nbsp;</span>

When rendering, a reference to the chosen object is made but it has not been defined on the instance. It seems like you are trying to check if a specific hero is included in this list

data() {
return {
  heroes: [
    { name: "Superman" },
    { name: "Batman" },
    { name: "Aquaman" },
    { name: "Wonder Woman" },
    { name: "Green Lantern" },
    { name: "Martian Manhunter" },
    { name: "Flash" }
  ],
  newName: "",
  isEdit: false,
  heroToModify: null
}

You can use any javascript expression within the v-if condition, for example:

<span v-if="heroes.map(heroObject => heroObject.name).includes(hero.name)">✔ &nbsp;</span>

In this case, I utilized Array.map() function to maintain objects within the list. You could opt-out by directly writing names in the array.

EDIT: For better reusability and clarity, consider using a computed property to avoid long expressions within v-if:

isInList(heroName) {
  return this.heroes.map(heroObject => heroObject.name).includes(heroName);
}

then

<span v-if="isInList(hero.name)">✔ &nbsp;</span>

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

Getting an UnhandledPromiseRejectionWarning while attempting to navigate through Google Maps using Node.js Puppeteer

(node:15348) UnhandledPromiseRejectionWarning: Error: Execution context was destroyed due to a potential navigation issue. const browser = await puppeteer.launch({headless: false}); const page = await browser.newPage(); page.goto("https://www.google. ...

What is the best way to implement a sidebar closing animation?

Utilizing both react and tailwindcss, I successfully crafted a sidebar menu that elegantly appears from left to right when the user clicks on the hamburger icon. However, my attempts to create a reverse animation as the sidebar disappears from right to lef ...

Finding the count of childNodes within a div using Selenium

I've been grappling with this issue for the majority of today; I'm trying to tally up the number of childNodes within a parent div. It's essentially mimicking a list where each childNode represents a row that I want to count. The HTML struct ...

Place a checkbox at the start of each table cell

Is there a way to add a checkbox before the text in the first cell of each row in an HTML table using jQuery? I attempted this method: $("table td:first-child").each(function() { $(this).prepend('<input type="checkbox" class="basic-kpi-row"/&g ...

A guide on breaking down a URL string containing parameters into an array with the help of JavaScript

I need help splitting a long string into an array with specific index structure like this: fname=bill&mname=&lname=jones&addr1=This%20House&... I am looking to have the array set up as shown below: myarray[0][0] = fname myarray[0][1] = b ...

ASP.NET WebMethod sends the entire webpage back to JQuery ajax requests

I've been working on a web application that involves calling an ASP.NET WebMethod from jQuery when a textbox is clicked. However, I'm encountering an issue where the WebMethod is returning the entire ASPX Page instead of just the values I need. H ...

What are some ways to prevent "window.onbeforeunload" from appearing when a form is submitted?

Is there a way to prevent the alert box from appearing when submitting a form using the Submit button below? I want to avoid being prompted to "Leave this page" or "stay on this" after submitting the form. <script> window.onbeforeunload = ...

Attempting to access JSON with AngularJS http.get() causes controller malfunction

Recently I've been diving into the world of AngularJS, and I encountered an issue while trying to parse a json file using the $http method. Initially, when testing a simple variable like $scope.test = "working";, everything seemed to be functioning co ...

Methods for dynamically updating a Django webpage without the need for a full page refresh

My Django application retrieves data from a database and updates it automatically without user interaction. I want the webpage to dynamically reflect these changes without having to reload the entire page. Using AJAX seems like the obvious solution. When ...

Why are JS & jQuery's inArray() and indexOf() functions not functioning correctly when indexes are strings?

Here is an example of an array: var arr = []; arr['A string'] = '123'; arr['Another string'] = '456'; I am attempting to find the index of either '123' or '456'. Both methods below are returnin ...

Why is Selectpicker failing to display JSON data with vue js?

After running $('.selectpicker').selectpicker('refresh'); in the console, I noticed that it is loading. Where exactly should I insert this code? This is my HTML code: <form action="" class="form-inline" onsubmit="return false;" me ...

The injector is currently updating the initial value in the test

I am currently testing one of my injectable components by using a provider to assign a mock value to APP_CONFIG. Here is the structure of the component: export let APP_CONFIG = new InjectionToken<any>('app.config'); @Injectable() export cl ...

Tips for setting focus on a previously hidden textbox in bootstrap after it has been revealed

Currently, I am in the process of developing a website using Bootstrap 3.3.6. On this site, there is a login form that becomes visible when the user clicks on the login button located above it (this functionality is already working). My goal now is to ens ...

Transferring a Picture via GupShup

Having trouble sending an image through GupShup using their sandbox environment. My backend utilizes node.js with feathersjs framework, but I keep encountering this error: Response { size: 0, timeout: 0, [Symbol(Body internals)]: { body: PassThro ...

Issue with AngularJS post request yielding status code 304 instead of successfully submitting data to backend server

I've put together a basic form structured like this: Here's the controller code: angular.module('clientApp') .controller('SignupCtrl', function ($scope, $http, $log, alertService, $location, userService) { $scope.si ...

Chrome freezing after long use of React app

Seeking help with troubleshooting a general problem in a JavaScript app I developed using React. The app receives streaming data from a websocket at a high frequency and updates the user display accordingly. However, after running for more than 12 hours, n ...

Navigate the child div while scrolling within the parent div

Is there a way to make the child div scroll until the end before allowing the page to continue scrolling when the user scrolls on the parent div? I attempted to use reverse logic Scrolling in child div ( fixed ) should scroll parent div Unfortunately, it ...

breaking up various dates into specific formatting using React

I need to convert a series of dates Wed Nov 13 2019 00:00:00 GMT+0000 (UTC),Tue Nov 19 2019 00:00:00 GMT+0000 (UTC),Tue Nov 19 2019 00:00:00 GMT+0000 (UTC) into the format 11/13/2019, 11/19/2019, 11/19/2019 ...

Dynamic AJAX Dependent Dropdown Menu

Can you help me create a dynamic input form? I need assistance in creating an input form with a dynamic dropdown list, similar to the screenshot provided below: https://i.stack.imgur.com/rFSqV.png What is my current script setup? The script I have is d ...

Determine whether the product is present, and if it is, verify whether the user is included in the array of objects

Whenever a button is clicked by a user, the system sends their userID along with the product ID to the query below. The goal is to validate if that specific product exists and then check if a particular userID exists within an array of objects in the sam ...