Passing a variable to a Vue component from the parent page that called it

Viewed 1545

I have a simple table that displays all of my data:

main file.php

<table class="table table-bordered table-hover" id="all-jobs">
    <thead>
        <tr>
            <th>{{ __('Job Name') }}</th>
            <th>{{ __('Job Description') }}</th>
            <th>{{ __('Job Status') }}</th>
            <th>{{ __('Job Applications') }}</th>
            <th>{{ __('Manage') }}</th>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td class="non_searchable"></td>
            <td class="non_searchable"></td>
        </tr>
    </thead>
</table>

<div id="app">
    <div id="editJob" class="modal fade in" role="dialog">
        <div class="modal-dialog">
            <!-- Modal content-->
            <div class="modal-content">
                <edit-job id=""></edit-job>
            </div>
        </div>
    </div>
</div> 

Now, I have a edit button that I am trying to open an edit modal for that specific row:

<a href='' data-id='{$job->id}' class='btn btn-xs btn-danger' data-toggle='modal' data-target='#editJob'><i class='fa fa-close'></i></a>";

The href is is location in one of the of my data table, I am trying to pass that to my .vue file so I can use it for my get and post requests:

myfile.vue

<template>
    <div>
       <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">×</button>
            <h4 class="modal-title">Edit Job</h4>
        </div>
        <div class="modal-body">
            <form method="post" @submit.prevent="signIn" @keydown="errors.clear($event.target.name)">
                <!-- Removed code, it's just inputs !-->
            </form>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-info btn-fill btn-wd" v-on:click="addJob">Save</button>
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
    </div>
</template>

<script>
    export default
    {
        props: ['id'],
        data: function () 
        {
            return {
                countries: [],
                name: '',
                summary: '',
                salarytype: '',
                salaryfrom: '',
                salaryto: '',
                location: '',
                contactemail: '',
                contactphone: '',
                errors: new Errors()
            }
        },

        methods: 
        {
            addJob: function()
            {
                axios.post('/jobs/edit', this.$data)
                .then(response => {
                    if(response.data.status === true){
                        $('#editJob').modal('hide');
                        getJobTable();
                    }
                    else{
                        formError = response.data.message;
                    }
                })
                .catch(error => this.errors.record(error.data))
            }
        },

        mounted: function()
        {
            console.log($(this).data('id'));
            axios.get('/jobs/my-job/')
                .then(response => {
                    this.name = response.data.name
                    this.summary = response.data.summary
                    this.salarytype = response.data.salary_type
                    this.salaryfrom = response.data.salary_from
                    this.salaryto = response.data.salary_to
                    this.location = response.data.location
                    this.contactemail = response.data.contact
                    this.contactphone = response.data.phone
                })

            axios.get('/countries')
                .then(response => {
                    this.countries = response.data;
                })
        }
    }
</script>

How can I past my href id to my to use for my request? Thanks

MY structure:

Created-jobs.blade.php

https://pastebin.com/TPBnC1qP

Edit-Job.vue

https://pastebin.com/30UWR5Nn

app.js

https://pastebin.com/1yxZWvVC

The table just populates the data, and adds the dropdown like so:

<ul class='icons-list'>
    <li class='dropdown'>
        <a href='#' class='dropdown-toggle' data-toggle='dropdown' aria-expanded='false'>
            <i class='icon-menu9'></i>
        </a>

        <ul class='dropdown-menu dropdown-menu-right'>
            <li>
                <a data-id='{$job->id}' onclick='getID({$job->id})' data-toggle='modal' data-target='#editJob'>
                    <i class='icon-file-pdf'></i> Edit Job
                </a>
            </li>
            <li>
                <a href='javascript:void();' data-id='{$job->id}' onclick='deleteJob({$job->id})'>
                    <i class='icon-cross'></i> Delete Job
                </a>
            </li>
        </ul>
    </li>
</ul>
1 Answers
Related