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

I have a simple table that displays all 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 an edit button in which I try to open the editing modal for this particular line:

<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>";

href is the location in one of my data tables, I am trying to transfer this to my .vue file so that I can use it for my receive and send 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 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 skip my href id for my use for my request? Thanks

MY structure:

Created by-jobs.blade.php

https://pastebin.com/TPBnC1qP

Edit-Job.vue

https://pastebin.com/30UWR5Nn

app.js

https://pastebin.com/1yxZWvVC

The table simply fills in the data and adds a drop-down menu like this:

<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>
+6
1

, , , Bootstrap. , id, Vue, Vue.

, , , , Vue , id , .

, main.js app.js :

import Vue from 'vue'
import EditJob from './EditJob.vue'

Vue.component('edit-job', EditJob)

const app = new Vue({
  el: '#app',
  data:{
   id: null 
  }
})

// Add a click handler for the links with the `data-id` property.
// This is using jQuery (because you are using Bootstrap) but you
// can do this any way you want.
$("[data-id]").on("click", function(){
  // Set the Vue data to the data-id property in the link.
  app.id = this.dataset.id
})

, new Vue(...) app. data, id Vue , app.id this.dataset.id , . , , , Vue id .

, , id .

<edit-job :id="id"></edit-job>

EditJob id.

.

Edit

, , jQuery script Created-jobs.blade.php. , , getID app, -, - javascript. app jQuery, window.

window.app = new Vue({
    el: '#app',
    data:{
        id: null
    }
});

-, getID, . . - jQuery- Created-jobs.blade.php ( ready).

$("[data-id]").on("click", getID)
+4

All Articles