The functionality of the Vueify modal seems to be malfunctioning when incorporating Vueify alongside a central Modal.vue file that houses modal templates

I've been experimenting with integrating this tutorial on creating reusable modal dialogs with Vuejs and adapting it for use with Vueify. Initially, I was able to successfully implement it, but after exploring a different approach briefly, I returned to encounter an issue where the modals were not appearing as expected but rather rendering directly on the page. My setup involves Laravel 5.2 and the latest version of Vue from a CDN included in my index.blade.php file.

Here's the structure of my Modal.vue component:

<template>
    <div class="modal-mask" @click="close" v-show="show" transition="modal">
        <div class="modal-container" @click.stop>
            <slot></slot>
        </div>
    </div>
</template>

<script lang="babel">

    export default {
        props: ['show', 'onClose'],
        methods: {
            close: function () {
                this.onClose();
            }
        },
        ready: function () {
            document.addEventListener("keydown", (e) => {
                if (this.show && e.keyCode == 27) {
                    this.onClose();
                }
            })
        }
    }
</script>

And here's the structure of NewSaleModal.vue:

<template>
    <modal :show.sync="show" :on-close="close">
        <div class="modal-header">
            <h3>New Post</h3>
        </div>

        <div class="modal-body">
            <label class="form-label">
                Title
                <input v-model="title" class="form-control">
            </label>
            <label class="form-label">
                Body
                <textarea v-model="body" rows="5" class="form-control"></textarea>
            </label>
        </div>

        <div class="modal-footer text-right">
            <button class="modal-default-button" @click="savePost()">
                Save
            </button>
        </div>
    </modal>
</template>

<script lang="babel">
    export default {
        props: ['show'],
            data: function () {
                return {
                    title: '',
                    body: ''
                }
            },
        methods: {
            close: function () {
                this.show = false;
                this.title = '';
                this.body = '';
            }
        }
    }
</script>

The initialization in App.js:

import Vue from 'vue';
import VueResource from 'vue-resource';
import Modal from './v-components/Modal.vue';
import NewSaleModal from './v-components/NewSaleModal.vue';

Vue.use(VueResource);

new Vue({
    el: '#app',
    components: {Modal, NewSaleModal},
    data: {
        showModal: false,
    }
});

Section from index.blade.php:

<div class="module" id="app">
        <new-sale-modal :show.sync="showModal"></new-sale-modal>
    <button id="show-modal" @click="showModal = true">New Post</button>
</div>

Instead of functioning as a modal, the content of NewSaleModal.vue is simply being rendered onto the page, visible here: https://i.stack.imgur.com/pGhw6.png. Despite no console errors being reported, both the "show" property within <NewSaleModal> and the "showModal" variable within <Root> are set to false.

Below are excerpts from my gulpfile and package.json files:

gulpfile.js:

var elixir = require('laravel-elixir');

require('laravel-elixir-vueify');

elixir(function(mix) {
    mix.less('main.less')
       .browserify('app.js')
       .version([
            './public/css/main.css',
            './public/js/app.js'
       ])
       .browserSync({proxy: 'site.dev'});
});

package.json:

{
  "name": "ProjectName",
  "version": "1.0.0",
  "devDependencies": {
    "browserify": "^13.0.0",
    "gulp": "^3.9.1",
    "laravel-elixir-vueify": "^1.0.3",
    "notify-send": "^0.1.2",
    "vue-resource": "^0.7.0",
    "vueify": "^8.3.9"
  },
  "dependencies": {
    "laravel-elixir": "^6.0.0-1",
    "laravel-elixir-browserify": "^0.8.1"
  }
}

If anyone can provide insights into why NewSaleModal.vue is not behaving as intended, I would greatly appreciate it.

Answer №1

It took me a while, but I finally came across the solution.

The mistake I was making was not including the Modal component in my NewSaleModal.vue file. So, I made sure to add

import Modal from './Modal.vue'

Right before the export default statement. Then, I included

components: {
        Modal
},

In the script itself and it resolved the issue I was having.

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

Pattern matching that incorporates certain conditions

I need a regular expression that satisfies two conditions: 1. It should not contain any white spaces. 2. It must contain either /, ., or both. The number of / or . can be one or more. $text = "Hi jaghdja ahja.ja//hda manmna.bnm bana na/bbnavn.com"; //for ...

When testing my jQuery locally, it runs smoothly. However, upon uploading it to my website, I encounter some issues where it

After successfully running my webpage on localhost, I encountered an issue when uploading it to my website. Only a portion of the code seems to be executing properly. I have included the following jquery function in my script and there are no reported err ...

Extracting key values from JSON using Node.js

Trying to read a json file using nodejs and locating a specific key within the object is my current task: fs.readFile('./output.json', 'utf8', function(err, data) { if (err) throw err; console.log(Object.keys(data)); } ...

Is it possible to implement zfdebug without relying on Zend_Application?

Currently, I am utilizing Zend Framework without incorporating Zend_Application, only specific classes - no Controller. I am wondering if there is a way to manually utilize zfdebug (calling it manually at the end of the script). I am struggling to find a s ...

FusionCharts Gauges may share similar code, but each one produces a unique output

Currently, I am developing a project that involves creating a dashboard with 3 gauges. These gauges are enclosed in bootstrap cards with a column value set to 4. In the layout of the dashboard, these 3 cards are positioned next to each other. I have succe ...

The problem encountered with the Enzyme mount API is a TypeError where it is unable to read the property 'find' of an undefined variable

After converting my component to a stateless one, I started encountering an error that says: TypeError: Cannot read property 'find' of undefined Previously, my tests were running smoothly before the switch. As far as I know, you can test functio ...

Making AngularJS work with angular-ui bootstrap and ensuring compatibility with IE8

Having trouble getting AngularJS code that utilizes angular-ui bootstrap to function properly in IE 8? Following the guidelines in the AngularJS developer guide on IE didn't seem to solve the issue for me. I inserted the code snippet below into my ind ...

Utilize ng-repeat to display a series of images, with the first image being placed within a unique div

My challenge lies in displaying product images using ng-repeat, where one image is located in a separate div. Let me share my code and explain what is happening. The API response provides product details and images [{"id_product":"1000","name":"Nikolaus ...

Verifying whether the user input consists of at least two words is essential

In order to ensure that the user has entered at least 2 words, it is necessary to validate their input using the "explode" method. If the input contains less than 2 words, an error message should be displayed. Here is a code snippet: <input type=" ...

Changing a single state in React results in the modification of both states simultaneously

Whenever I attempt to modify one state, I find that another state is inexplicably changing as well. I've scoured my code for the issue but can't seem to pinpoint it. What steps should I take next? Here's the snippet of code in question: impo ...

Tips for incorporating a PHP heredoc into an array as a value

Currently, I am facing a challenge with inserting a large block of multi-line text into a PHP associative array using a heredoc. The code snippet in question is as follows: $data = [ "x" => "y", "foo" => "bar", /* ... other values ... */ "idx ...

Ensuring that md-select(s) created through ng-repeat are linked to the same model

<div ng-repeat="(key, value) in dataSet | groupBy: 'partner.partnerName'"> <md-select ng-model="userName" placeholder="{{ key }}" class="partnerUser" > <md-option >{{ key }} </md-option> <md-option ng-repe ...

Firebase Error: Page Not Found

I recently set up an Angular2 application and added Firebase using npm. I successfully imported it into my app.component.ts without any errors showing up in my text editor. The package.json file also indicates that Firebase is installed correctly. However ...

Angular - automated pagination functionality without requiring user input

I apologize for the poorly worded title. Context In my static display angular app, I am not incorporating any user interactions and most actions are time-based. The page loads, and after a specific amount of time determined by certain elements, it reload ...

"Can someone show me the process of extracting data from a URL using preg_match

Here is a link to my website: <a href="http://example.com/post/12345">sample_post</a> I am trying to extract the URL using preg_match_all(); http://example.com/post/12345 Any assistance would be appreciated. ...

Controlling the document object model of a third-party website within the Electron framework

I am completely new to electron. My main goal is to load a URL and then execute some Javascript that will make changes to the DOM. Currently, my approach involves creating a BrowserWindow that loads the URL, and I understand that I can utilize webContents ...

Using PHP to combine MySQL tables and then displaying the results in a neatly organized JSON

Struggling to merge data from two MySQL tables in my PHP script and transform it into JSON for use in our internal art team app. This tool is exclusively designed for making edits to products created by our company. The main goal is to generate a product ...

Incorporating scope injection similar to AngularJS into newer libraries

My current platform is built using AngularJS, and I'm considering transitioning to a more modern framework in the future. However, I have concerns about dynamic scope injection when it comes to ES6, Webpack, and TypeScript. Our use-case involves dynam ...

Having trouble with the isset($_POST[] ) function?

I found this file upload.html where the following code is located, and every time I browse a file and submit it fails at isset($_POST). It then echoes "didn't upload". Interestingly, it works fine with the same file in another folder. The only change ...

Prevented a frame from "https://googleads.g.doubleclick.net" from accessing another frame

After placing ads on my website, they are displaying properly. However, I am receiving an error repeatedly in the console when the page loads: A frame from origin "" is being blocked from accessing a frame with origin "". The requesting frame has an "ht ...