Is it possible to use bootbox with Vue.js?


#1

I have a little form, in which is a pop-up with options which can be selected via checkboxes. I have to realise it with Vue.js and bootbox. I am using the bootstrap-vue plugin.

When I run it I get the following error messages:

“Uncaught SyntaxError: Unexpected token < bootbox.min.js:1”

“Uncaught Error: $.fn.modal is not defined; please double check you have included the Bootstrap JavaScript library. See http://getbootstrap.com/javascript/ for more details. bootbox.js:584”

I installed the npm package. I added

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
    <script src="bootbox.min.js"></script>

to the body of my index.html. And I added

var bootbox = require('bootbox');

to the *.vue component.
This is my code:

<script>
import JQuery from 'jquery'
let $ = JQuery
var bootbox = require('bootbox');

export default {
    name: 'eingabe',
    data: function () {
        return {
            kundeUebertrag: '',
            ergebniseins: '',
            ergebniszwei: '',
            ergebnisstring: '',
            ergebnisstring2: '',
            kundeNummer: '',
            bereichNummer: '',
            eventNummer: '',
            siteId: '',
            obj: '',
            ergarray: [],
            innerobj1: '',
            innerobj2: '',
            feldSichtbar: 'none'

        }
    },


    methods: {
        aufrufeins: function() {
            let vm = this;
            let neueDaten = document.formular;
            neueDaten.addEventListener('submit',function(evt) {
                evt.preventDefault();
            });

            vm.kundeUebertrag = vm.kundeMatomo;
            $.getJSON("/api/pruefung.php", { kundeUebertrag: 
                this.kundeUebertrag}, function (result) {
                vm.ergebniseins = result;                           
                vm.ergebnisstring = vm.ergebniseins[0];               
                vm.ergebnisstring2 = vm.ergebnisstring.returnmeldung;
                vm.obj = JSON.parse(vm.ergebnisstring2);
                if(vm.obj.status == "neuanlage")
                {
                    vm.siteId = vm.obj.siteid;
                }
                if(vm.obj.status == "rueckfrage")
                {
                    for (var prop in vm.obj)
                    {
                        vm.innerobj1 = vm.obj[prop][0];
                        for (var props in vm.innerobj1)
                        {
                            vm.innerobj2 = vm.innerobj1[props][0];
                            console.log(vm.innerobj2.kunde)
                            vm.ergarray.push(vm.innerobj2);

                        }
                    }
                    vm.ergebniseins = vm.ergebnisstring2;               
                    vm.feldSichtbar = 'block';
                    bootbox.prompt({
                        title: "Bitte einen Kunden auswählen",
                        inputType: 'checkbox',
                        inputOptions: [
                            {
                                text: 'Choice One',
                                value: '1',
                            },
                            {
                                text: 'Choice Two',
                                value: '2',
                            },
                            {
                                text: 'Choice Three',
                                value: '3',
                            }
                        ],
                        callback: function (result) {
                            console.log(result);
                        }
                    });

                }
            });
        },


    }
}
</script>

I expect the bootbox to appear, but nothing appears. Only error messages. Is it in general possible to use Vue.js with bootbox? What do I have to do?


#2

I found the error. “require(‘bootstrap’)” was missing in the vue file.