Sending an attribute to the Treeselect Vue component from a Laravel view

I want to encapsulate Vue-Treeselect link: within its own custom vue component. This way, I can easily use something like

<tree-select></tree-select>
in a Laravel view file where needed.

However, the challenge I'm facing is figuring out how to pass specific props from the Laravel view to the component and then utilize those attribute values inside the template. For instance, I would like to pass a field name from the Laravel view like this:

<tree-select name='property_ids'></tree-select>
. Afterwards, the vue component template should be able to access and use this passed-in name for the `name` attribute within the template itself.

Currently, I am following the Getting Started guide on . In my Laravel form view, I envision including this tag:

<tree-select name='property_ids'></tree-select>
But the question remains: How do I dynamically set the value of the `name` attribute inside the vue component template as shown below?

<template>
    <div>
        <treeselect v-model="value" :multiple="true" :options="options" name="passedInName"></treeselect>
    </div>
</template>

<script>
    // import the component
    import Treeselect from '@riophae/vue-treeselect'
    // import the styles
    import '@riophae/vue-treeselect/dist/vue-treeselect.css'

    export default {
        // register the component
        components: { Treeselect },
        data() {
            return {
                // define the default value
                value: [],
                // define options
                options: [  {
                    id: 'b',
                    label: 'b',
                }, {
                    id: 'z',
                    label: 'z',
                }, {
                    id: 'x',
                    label: 'x',
                } , {
                    id: 'v',
                    label: 'v',
                }],
            }
        },
    }
</script>

Answer №1

Remember to define the props that are passed into your Vue component so that they can be used in the template.

<template>
    <div>
        <!-- Make sure to pass the prop to the appropriate attribute -->
        <treeselect v-model="value" :multiple="true" :options="options" :name="this.name">
        </treeselect>
    </div>
</template>

<script>
export default {
    props: ['name'], // <-- Prop declaration 
};
</script>

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

How to retrieve the index number of a clicked tab in Bootstrap 4?

I'm currently working on identifying the index of the tab clicked by the user within a group of tabs. For example, if there are five tabs and the user clicks on the second one. To calculate the total number of tabs, I can assign an ID to the navigati ...

Using jQuery to track the status of checkboxes

Changing the checkbox status using the code: $(this).attr("checked", 'checked'); However, when trying to check the checkbox status afterwards, I received the following results: $(this).attr('checked'): "checked" $(this).is(':chec ...

Issue encountered while trying to utilize the reset function of the FormGroup with the angular2-tinymce plugin

I utilized the FormGroup feature to construct my form, and I required a textarea component. I decided to use the angular2-tinymce library/package to create the form. Here is my HTML template: <form (submit)="submitCallLog($event)" [formGroup]="callLo ...

Searching for a single cell within an HTML table

I've been on the hunt for a code that can search through a table and show just one cell. I tried creating my own, but finally stumbled upon one that seems to work perfectly, except for one hiccup. When the search bar is cleared, it displays the first ...

A tutorial on how to switch classes between two tabs with a click event in Vue.js

I am having an issue with my spans. I want to implement a feature where clicking on one tab changes its color to red while the other remains gray. I have tried using class binding in my logic but it's not working. How can I solve this problem and make ...

JavaScript namespace problems

Although I am using a namespace, the function name is getting mixed up. When I call nwFunc.callMe() or $.Test1.callTest(), it ends up executing _testFunction() from the doOneThing instead of the expected _testFunction() in the $.Test1 API. How can I correc ...

What is the best approach to determine the value of a textbox in an array for each row of

I am trying to display the total sum of values for each row in a data array. There are 5 rows of data, and I need to calculate the results for each one. Can someone assist me in solving this? function calculateTotalValue(){ var total = (document.get ...

What is the process for implementing the sticky table header jQuery plugin?

I am looking to implement a sticky header on all tables in my web application, which is built on PHP. As the amount of data continues to grow, search results are fetching more records that may not be visible. I am primarily a PHP programmer and do not have ...

Leveraging a function for filtering in AngularJS

I have developed an application where the content filter changes depending on which button is clicked. I have managed to figure out the straightforward filters, but now I am attempting to create a filter that displays content within a specified range. Bel ...

ReactJS | Display or Conceal an Array of Objects depending on a specified condition

The Challenge: I am currently working on a task that involves hiding/showing react elements dynamically based on a property of the constructed Object. To be more specific, let's consider the Array of Objects below: const Apps = [ {name: App1, permi ...

Issues with React Router server-side rendering: Error: Required prop 'history' was not specified in 'RoutingContext' prop validation

I am currently working on a fun little project to improve my React/Hapi skills and so far everything has been smooth sailing until I attempted to set up server-side routing. The server is running without any issues and successfully renders "/" with a simpl ...

What is the best way to retrieve the column that comes after a specific column?

I have a specific column and I want to extract the subsequent column in the dataset. nhood,column,variablecolumn Treasure Island,3,5 McLaren Park,1,2 Tenderloin,28,112 Lakeshore,14,8 Chinatown,15,103 Although I know the name of the second column, the na ...

Unit testing AngularJS service with promise

Could use some assistance with unit testing a service that relies on a repository returning a promise to the consumer. Struggling to figure out how to properly test the promise. Any guidance would be welcomed! ...

Default cursor for Internet Explorer: automatic

I have a container div that holds all of my website's content. I want this container to change the cursor to a pointer when clicked on, but I don't want the elements inside the container to inherit this cursor style: https://i.sstatic.net/8joJo. ...

Issue with function incorrectly computing values and returning NaN

My challenge is to develop a countdown timer, but it keeps returning NaN instead of counting down. I have multiple counters in place - one that counts down, another that counts up until the stop time specified by stoptime, and a third that kicks in after s ...

Is there a way to implement a @click event on a Vuetify expansion panel?

Whenever I use <a>, the design of the <v-btn> expansion panel breaks. How can I incorporate the click event in this situation? I attempted to utilize filters, watch, and computed, but it didn't work. Here's my code: <v-card xs1 ...

Resolving Cross-Domain Ajax for Improved API Performance

In the midst of developing an infrastructure to support a gaming platform that will cater to a large user base, performance is our top priority. We are striving to parallelize the architecture by running APIs, databases, and applications on separate server ...

The background on my modal remains unchanged

I have integrated a modal using Iframe for user login/registration on my website. Here is the HTML code: <div class="modal" id="ays-popin-connexion" aria-hidden="true"> <div class="modal-body" aria-hidden="true"> <iframe src=" ...

Utilizing the POST route as a middleware: a step-by-step guide

I am working on 2 different routes users.js POST api/users auth.js POST api/auth/confirmation My goal is to utilize the auth/confirmation as middleware in the /users route Initially, I attempted to create a temporary function and use res.redirect(... ...

Issue with Generating PDF File: Live Server Showing 403 Error

I am attempting to create a pdf file using the mPDF library in php. See below for my code: Initially, I am sending a large amount of data that needs to be written into the pdf file. JS: $.ajax({ url: '/backend_pdfgen/pdfgen.php', type: ...