Sending information to a singular Vue component file

Struggling to pass data to props and render different content in a component on each page? Want to display links, tech, feedback without deleting the component or rewriting code for individual pages? Existing methods not working for you? Unsure if what you're attempting is feasible?

component.vue

<template>
<el-collapse v-model="activeName" @change="handleChange" accordion>
    <el-collapse-item title="Links" v-model="links">
        <center>{{ this.links }}</center>
        </el-collapse-item>
        <el-collapse-item title="Tech" name="2" prop-name="techlist" v-model="techlist">
            <div v-for="o in this.techlist" :key="o" class="text item" >
                {{ o }}
            </div>
        </el-collapse-item>
        <el-collapse-item title="Feedback" name="3" v-model="feedback">
            {{ this.feedback }}
        </el-collapse-item>
    </el-collapse>
</template>


<script>
export default {
    props: ['links', 'techlist', 'feedback']
}
</script>

page.vue

<template>
    <div>
        <el-row class="bg-row" type="flex" justify="end">
            <el-col span="6">
                <v-menu>
                </v-menu>   
            </el-col>
        </el-row>
    </div>           
</template>

<script>
import Menu from 'components/Menu'

export default {
  name: 'page2',
     data() {
      return {
          techlist: ["tech1", "tech2","tech3"],
          links: "<center><a href='page1'>Github</a><br><a href='page2'>heroku</a></center>",
          feedback: '<div>Basically just a placehold for feature I will add to the site later on.</div>'
        }
    },
    components: {
        'v-menu': Menu
    },
}
</script>

Answer №1

While you have correctly defined your props within the component itself, it is important to remember to bind or pass them from the parent component. In the parent component, make sure to include them in this manner:

<v-menu :links="links" :techlist="techlist" :feedback="feedback"></v-menu>

The :links part should match the name you use in props:['links']. The ="links" part represents the data property, method, or computed property defined in the parent component. For instance, you could use :links="getLinks()", where 'getLinks()' is a method that retrieves all links.

https://v2.vuejs.org/v2/guide/components.html#Props

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

Tips for Deactivating a Button Following a Single Click

I am currently developing a react-native app and I'm in need of assistance with my code stack. My requirement is to disable a button after it has been clicked once. Can anyone provide guidance on this issue? The challenge I am facing is that I cannot ...

Implementing ordering and limiting of elements in NestJS TypeORM relations

I am new to typeorm and relationships. I am currently facing some challenges and feeling a bit confused. I have a question regarding sorting relations in typeorm by id or createdDate without explicitly mapping them and limiting the number of elements. Here ...

What could be the issue causing Vue to not start up properly?

I have been working on a Rails application and have integrated some Vue components into the pages. The components range from simple dynamic lists to more complex implementations with nested components. Let me walk you through how it all functions with som ...

reveal.js: Upon a fresh installation, an error has been encountered: ReferenceError - 'navigator'

Currently, I am attempting to integrate reveal.js into my React.js/Next.js website using the instructions provided at However, upon implementation, I encountered the following error: Server Error ReferenceError: navigator is not defined This error occurr ...

Tips for presenting the retrieved data from the database in a user-friendly format

$ //First step involves running the PHP code that executes the SQL query to retrieve data from the database, storing it in get_row1, and sending it as a response to Ajax$ <?php $connect = mysql_connect("localhost", "root", ""); $data = mysq ...

Update a class based on a specified condition

Can I streamline the process of adding or removing a class from an element based on a variable's truthiness? Currently, my code seems overly complex: if (myConditionIsMet) { myEl.classList.add("myClass"); } else { myEl.classList.remove("myClass"); ...

How can escape characters be utilized in the JavaScript split function?

Here are two examples that achieve the same result. I'm curious as to why Option 1 was included in a code example I came across instead of Option 2? What is the significance of the forward/backward slashes in '/\&/'? Option 1: ...

Every time I try to set up the MailChimp pop-up javascript, I encounter an Uncaught Error message saying that Bootstrap tooltips need Tether and an Uncaught ReferenceError message

Utilizing Wordpress and Understrap. Upon inserting the following code: <script type="text/javascript" src="//downloads.mailchimp.com/js/signup- forms/popup/embed.js" data-dojo-config="usePlainJson: true, isDebug: false"> </script><script ty ...

Switch Selector for React Native

Although it may seem simple, I'm having trouble getting a function to automatically switch between the "user" and "business" options on the switch selector without requiring manual input from the user. I attempted to use: const switchRef = useRef(nu ...

What is the best way to ensure that the div from the header file remains fixed directly above the fixed div from another file?

This is the header section that I want to keep fixed within the "header" div. <div id="header" style="display:block;"> <table style="width:100%"> <tr> <td class="col-sm-6" style="background-color:lavender;"><a href ...

Connecting a Vue component to a Django HTML template

I have a Django project that includes multiple templates structured like this: <body> <div> <ul> <li> <a href="#"> customers &l ...

Is it possible to prevent the text from appearing in the text box when a button is

I have successfully implemented a feature where clicking on the button (click on me) in HTML displays a textbox along with another button (show) on the screen. The text written in the textbox is visible when the show button is clicked. However, after the i ...

Tips to prevent the webpage from scrolling to the top when clicking on an anchor with an ID

I have developed a CSS/HTML carousel that consists of 4 slides. The goal is to display the selected slide when clicking on the bottom button (a href). However, I am facing an issue where every time I click on a link, the selected slide appears as intended ...

Incorporating the id attribute into the FormControl element or its parent in Angular 7

I'm attempting to assign an id attribute to the first invalid form control upon form submission using Angular reactive forms. Here is my current component code: onSubmit() { if (this.form.invalid) { this.scrollToError(); } else { ...

Utilizing PHP and Ajax to showcase individual row details within a while loop upon clicking a hyperlink

In the midst of a new project, I find myself faced with a task where the user can log in and view their personal delivery orders. The list of deliveries is generated using a while loop. However, whenever I click on the details button for an item in the lis ...

Tips for running multiple .js test files simultaneously with npm (pact files)

My background is in Java and Maven, where I am accustomed to running multiple test files together and sequentially using a command like: mvn '-Dtest=com.my.directory.tests.*Test' test In this setup, all my test files are named to end with the w ...

No need for jQuery with this scrolling image gallery

I recently created a horizontal scrolling image gallery with thumbnails underneath. The goal is to click on a thumbnail and have the corresponding image scroll into view. Here's the HTML setup: <div class="images_container"> <img id="imag ...

Tips for incorporating WinBox JS into Angular applications

I've been experimenting with the WinBoxJS JavaScript library, and I'm familiar with using it in plain JS. However, I'm now attempting to integrate it into my Angular project. Can anyone guide me on how to achieve this? https://www.npmjs.com/ ...

What is the process of encapsulating a callback function within another callback function and invoking it from there?

Here is the code snippet I am working with: var me = this; gapi.auth.authorize({ client_id: client, scope: scope, immediate: true }, function (authResult: any) { if (authResult && !authResult.error) { me ...

Combining Django, Graphene, Apollo, django-webpack-loader, and Vue: Struggling with CORS and CSRF compatibility issues?

Currently, I am immersed in a project that involves Django as the backend, Vue as the frontend, and Apollo/Graphene/GraphQL as the data transfer layer. While most of it is functioning smoothly, I am encountering difficulties with the CORS/CSRF settings. I ...