What is the solution to the error "modal is not defined" in Vue.js?

Hey guys, I need some help with an error that popped up: [Vue warn]: Error in v-on handler: "TypeError: $(...).modal is not a function". The issue is with the modal function Below is the code snippet from my welcome.blade.php:

<body>
    <div id="app">
        {{-- This is the vue component --}}
        <new-arrivals></new-arrivals>
    </div>
    <!-- Scripts -->
    <script src="{{ asset('js/app.js') }}" defer></script>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</body>

This is the content of my js/app.js file:

require('./bootstrap');

import Vue from 'vue'
import { VueCtkDateTimePicker } from 'vue-ctk-date-time-picker';
import swal from 'sweetalert2';
import 'vue-ctk-date-time-picker/dist/vue-ctk-date-time-picker.css';
// import $ from 'jquery';
// window.$ = $;
window.Vue = require('vue');
window.swal = swal;
Vue.component('VueCtkDateTimePicker', VueCtkDateTimePicker);
Vue.component('new-arrivals', require('./components/NewArrivals.vue').default);


const app = new Vue({
    el: '#app'
});

And finally, here is the script from my Vue component:

<script type="text/javascript">
import axios from 'axios'

export default {
  data(){
      return {
      }
  },
  methods: {  
    openModal(){
        $('#create_form_modal').modal('show');
    }
  }
}
</script>

Answer №1

Encountered a similar issue: Bootstrap modal error: not functioning

This problem arose due to the incorrect order in which scripts were loaded. To resolve, try loading the scripts in the following order:

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="{{ asset('js/app.js') }}" defer></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

Error: Attempting to iterate over an undefined property in a Laravel and Vue.js application

Hey there! I've been running into an issue while trying to count the length of notifications using vue.js and Laravel. Every time I do this, I get an error saying "Uncaught (in promise) TypeError: Cannot read property 'forEach' of undefined" ...

When the browser is not in the foreground, clicking on the Bootstrap datepicker with Selenium does not register

When you click on the input field <input id="dp1" class="span2" type="text" value="02-16-2012"> If the browser is in the background, the datepicker popup will not display. Even using javascript or jquery to click the input field does not show the ...

Issue with two Jquery slider forms

Within a Jquery slider, I have implemented two distinct forms (using this specific Jquery slider: http://tympanus.net/Tutorials/FancySlidingForm/) . My goal now is to establish JavaScript/jQuery validation for these two forms separately BASED on the form ...

Transform JSON data into a JavaScript variable

Just diving into the world of Node.js and JavaScript. Please forgive me if my question seems basic. Here is a snippet of my Node.js code that retrieves data from MySQL: var quer = connection.query('select password from users where mail="' ...

A method designed to accept an acronym as an argument and output the corresponding full name text

Having trouble with my current task - I've got an HTML file and external JS file, and I need a function that takes an element from the 'cities' array as input and returns a string to be used in populating a table. I've set up a functio ...

The error message in React Hook Form states that the handleSubmit function is not recognized

I'm facing an issue with using react-hook-form for capturing user input. React keeps throwing an error that says "handleSubmit is not a function". Any suggestions on how to resolve this would be highly appreciated. Here's the code snippet I&apos ...

Currently Engaged in Seeking Out a Specific Phrase and Substituting it

Input fields are situated on one side of the page and their content is then displayed in organized boxes on the other side. I am looking to search for a specific string, 'key', within the input fields and replace it with a predefined value stored ...

Creating a Dynamic Bar in Your Shiny Application: A Step-by-Step Guide

Currently, I am developing a unique crowd funding shiny app to monitor donation amounts. Is there a method available that allows for the creation of a reactive bar in Shiny? Alternatively, is it feasible to achieve this using html, css, and javascript? He ...

Cropper.js, effortlessly populating a container with a perfectly centered image

I took inspiration from the cropper.js library website but made modifications. You can check out the original example here. Here's my version of the modified example: CodePen Link var image1 var cropper1 var image2 var cropper2 ...

transferring information between controllers and saving it persistently in AngularJS even after refreshing the

What is the best way to share data (Object) between controllers with different routes and prevent data loss after a page reload? I have an object that I need to use to prefill form values on my destination page based on choices made on my source page. S ...

React - How to Close Material-UI Drawer from a Nested Menu

Currently, I am utilizing a fantastic example (here) to create a dynamic nested menu for my application. Taking it a step further, I am trying to integrate it into a Material UI appbar/temporary drawer. My goal is to close the drawer when the user clicks o ...

Sharing data between two Angular 2 component TypeScript files

I'm facing a scenario where I have two components that are not directly related as parent and child, but I need to transfer a value from component A to component B. For example: In src/abc/cde/uij/componentA.ts, there is a variable CustomerId = "sss ...

A guide on extracting split values and assigning them to individual variables

Currently, I'm working on a project utilizing node.js, express, mongo, and socket.io. After successfully retrieving geolocation coordinates and storing them in a hidden input field, I encountered an issue when attempting to save the data into the data ...

The redirection to the webpage is not occurring as expected

I've been attempting to redirect another webpage from the homepage in my node server. However, the redirect isn't working as intended to link to idea.html, where the relevant HTML file is located. Can anyone assist me in identifying any errors in ...

Sharing data from parent to child components in Vue.js: A guide to passing references

I need some help with this code snippet HTML Code: <div class="col-xs-4"> <h3 class="text-center">Incomplete task</h3> <div class="well" style="max-height: 300px;overflow: auto;"> <ul id="check-list-box" ...

Replicating row with distinct values

I'm experiencing some difficulties with a particular issue. I currently have two tables as shown below: <table id="customFields1" class="table table-bordered table-hover additionalMargin alignment"> <thead> <tr> < ...

AngularJS written plugin in Javascript

I developed an app using Rails and AngularJS. A startup has reached out to me about transferring the technology to their website, but they have limited tech resources. The goal is to create a seamless integration process. The idea is to make it similar to ...

Best practice for sending a Facebook token securely between client and server

I'm facing a dilemma on how to securely transfer a user's Facebook token from their client to my server. Currently, I have the following approach in mind: The user accesses a webpage and logs in to Facebook; Facebook token is obtained; User&apo ...

Utilizing node.js for manipulating files (JSON) through reading and writing operations

There is an issue with my function that reads a JSON file and updates it using the fs.writeFile method. When I invoke this function multiple times, it fails to update the file properly. After the first call, it adds extra curly brackets at the end of the J ...

Calculating the total of values in a vuejs and laravel table

I need assistance with calculating the total amount in a table that includes quantity, unit price, and their totals using Vue.js and Laravel. I am looking to loop through the database elements and only display certain elements via v-if. Any guidance on how ...