1

I'm working in a vue component for my application in Laravel 5.3, I try to integrate the Laravel File Manager in a standalone button, but this not working, nothing happend when I clic on the button for choose an image, this component required a jQuery init setup, like the following line:

$('.lfm-img').filemanager('image');

I checked the component outside the .vue file and its working fine, only inside the .vue file is not working.

This is the vue component

<template>
    <div class="modal fade" 
            id="section-{{ section.id }}" 
            tabindex="-1" 
            role="dialog" 
            aria-labelledby="sectionLabel-{{ section.id }}">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" 
                            class="close" 
                            data-dismiss="modal" 
                            aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                    </button>

                    <h4 class="modal-title" id="sectionLabel-{{ section.id }}">
                        {{ section.name }}
                    </h4>
                </div>
                <div class="modal-body">
                    <!-- Field List -->
                    <div v-if="editing != true">
                        <ul class="list-group">
                            <li class="list-group-item" v-for="field in fields">
                                <div class="clearfix">
                                    <div class="pull-left">
                                        <span>
                                            {{ field.name }}
                                        </span>
                                    </div>
                                    <div class="pull-right">
                                        <button type="button" 
                                                class="btn btn-default" 
                                                data-toggle="tooltip" 
                                                title="Editar valor"
                                                @click="setField(field)">

                                            <i  class="fa fa-pencil-square fa-lg" 
                                                aria-hidden="true"></i>
                                        </button>
                                    </div>
                                </div>
                            </li>
                        </ul> 
                    </div>
                    <!-- / Field List -->
                    <!-- Save value form -->
                    <div v-else>
                        <form @submit.prevent="updateFieldValue()">
                            <!-- Fields types -->
                            <div v-if="field.fieldtype_id === 1">
                                <div class="form-group vertical-align">
                                    <label class="col-md-2 text-right">
                                        Texto
                                    </label>
                                    <div class="col-md-10">
                                        <input  type="text" 
                                                v-model="value" 
                                                placeholder="Ingrese el valor"
                                                class="form-control"
                                                required="required">
                                    </div>
                                </div>
                                <p><br></p>
                            </div>
                            <div v-if="field.fieldtype_id === 2">
                                <div class="form-group">
                                    <textarea   v-model="value" 
                                                placeholder="Ingrese texto"
                                                class="form-control"
                                                rows="5"
                                                required="required">
                                    </textarea>
                                </div>
                                <p><br></p>
                            </div>
                            <div v-if="field.fieldtype_id === 3">
                                <div class="form-group vertical-align">
                                    <label class="col-md-3 text-right">
                                        Seleccione una imagen
                                    </label>
                                    <div class="col-md-9">
                                        <div class="input-group">
                                            <span class="input-group-btn">
                                                <a  data-input="value" 
                                                    data-preview="holder" 
                                                    class="btn btn-primary lfm-img">
                                                    <i  class="fa fa-picture-o"
                                                        aria-hidden="true"></i> Seleccionar
                                                </a>
                                            </span>
                                            <input  id="value" 
                                                    v-model="value" 
                                                    class="form-control" 
                                                    type="text" 
                                                    name="value"
                                                    required="required">
                                        </div>
                                    </div>
                                </div>
                                <img id="holder" style="margin-top:15px;max-height:100px;">
                                <p><br></p>
                            </div>

                            <!-- Actions -->
                            <div class="clearfix">
                                <div class="pull-right">
                                    <button type="button" 
                                            class="btn btn-default" 
                                            data-dismiss="modal" 
                                            @click="finishEdit()">
                                            Cancelar
                                    </button>
                                    <button type="submit" 
                                            class="btn btn-primary">
                                            Guardar
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <!-- / Save value form -->
                </div>
                <div class="modal-footer">
                    <button type="button" 
                            class="btn btn-default" 
                            @click="finishEdit()" 
                            data-dismiss="modal">
                            Cerrar
                    </button>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        props: ['section'],

        data() 
        {
            return {
                fields: [],
                field: [],
                value: '',
                loading: true, // start the spin loader
                editing: false // show field list
            }
        },

        ready()
        {
            this.loading = false; // stop the spin loader
            this.getSectionFields();
        },

        methods: 
        {   
            startEdit()
            {
                this.editing = true;
            },

            finishEdit()
            {
                this.field = [];
                this.value = '';
                this.editing = false;
            },

            setField(field) {
                this.field = field;
                if (this.field.pivot.value !== null) {
                    this.value = this.field.pivot.value;
                }
                this.startEdit();
            },

            getSectionFields()
            {   
                var self = this; // store "this." scope
                // GET request
                this.$http.get('/api/getSectionFields/' + this.section.id )
                    .then((response) => {
                    // sucess callback
                    var json = JSON.parse(response.body); // json parse
                    self.fields = json.fields;
                    this.loading = false; // stop the spin loader
                }, function(response) {
                    // error callback
                    console.log(response);
                });
            },

            updateFieldValue()
            {   
                this.loading = true // start the spin loader
                var params = {  section : this.section.id, 
                                field : this.field.id, 
                                value : this.value 
                            };
                // POST request
                this.$http.post('/api/update-value', params)
                    .then((response) => {
                    // sucess callback
                    this.getSectionFields();
                    this.finishEdit();
                }, function(response) {
                    // error callback
                    console.log(response);
                    this.getSectionFields();
                });
            }
        }
    }
</script>
2
  • Please post your code here, rather than a link to an external site. Commented Mar 27, 2017 at 21:45
  • @dash2 Sorry for the link, I already pasted the code Commented Mar 27, 2017 at 22:11

1 Answer 1

2

I solved the problem using Vue.nextTick, running the following code before the file manager be shown to ensure the initialization of the plugins in the latest DOOM update.

initFilemanager() 
{
    this.$nextTick(function() {
        $('.lfm-img').filemanager('image');
    });
},
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this was a huge help-- any chance of an explanation of what this does? My WYSIWYG was rendering properly, but none of the toolbar stuff in it was responding to clicks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.