Retrieving the value of a custom component's prop in a Vue application

I recently created a custom checkmark that I'm using.

Vue.component('checkle', {
    props: ['crisis'],
    template: '<input type="checkbox" class="form-check-input" />',
    mounted: function() {
        var vm = this
        $(this.$el).on('change', function() {
            vm.$emit('change')
        })
    }
})

            <checkle crisis="crisisvalue"
                     v-model="Model"
                     @change="changeLEC()" :disabled="!SomeValue">
            </checkle>

In my Vue App, I have defined @change, but I am unsure how to access the crisis prop within my app. Does anyone know if there is a way to accomplish this?

Answer №1

Click here to learn more about handling events in Vue.js

To access props directly by name, you can use the following syntax:

@change="changeLEC(crisis)"

Alternatively, you can reference this.crisis inside the changeLEC method. This prop should be provided to your component as part of the methods: property of your component object.

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

Typedoc Error: Attempted to assign a value to an undefined option (mode)

After installing typedoc with the command npm install typedoc --save-dev, I proceeded to add typedocOptions to tsconfig.json: { "compileOnSave": false, "compilerOptions": { "baseUrl": "./", // ...some lin ...

What is the reason for the global impact of CSS-Modules on html elements?

There is a file named mycomponent.module.css button { width: 10vw; min-width: 150px; } It seems like this CSS is being applied globally instead of just to the specific component where I imported it. Could it be that CSS modules only work on class ...

"Utilizing Node.js with Express and Passport to implement JWT authentication - executing functions after

I have successfully implemented authentication using passport JWT, but I am facing challenges in executing a callback function/response only when a user is authenticated. How can I achieve this? Here is how my routes are set up: import express from &apos ...

The Vue production build displays a blank page despite all assets being successfully loaded

After running npm run build, I noticed that my vue production build was displaying a blank page with the styled background color from my CSS applied. Looking at the page source, I saw that the JS code was loading correctly but the content inside my app d ...

Is it not the case that using spread syntax does not make a reference to the original array?

I am currently facing an issue with my React application. I have two Object arrays in my state, one called names and the other called shuffledNames. I am attempting to create a copy of the names array and shuffle it into the shuffledNames array. However, w ...

Verify whether a dependency is being passed into an Angular component

As mentioned in a discussion about IE caching issues, Internet Explorer tends to cache things when using ajax with AngularJS, causing potential problems. You can find a helpful solution to this problem here. Given that we have multiple angular apps on our ...

Changing the play state of the animation is causing synchronization issues with my audio

As I work on syncing a scroll effect animation in a div with an audio file, I've encountered an issue. The synchronization works perfectly when I set the element.style.animation property to 'none' when the audio is paused. However, things ge ...

Page is restricted to uploading only a single image at a time

I'm currently working on setting up a simple server that can handle both POST and GET requests. The goal is to allow users to upload images to a directory while saving relevant data like date, name, description, and id to a JSON file. In the case of a ...

Is there a way to verify if a user taps outside a component in react-native?

I have implemented a custom select feature, but I am facing an issue with closing it when clicking outside the select or options. The "button" is essentially a TouchableOpacity, and upon clicking on it, the list of options appears. Currently, I can only cl ...

Angular applications with separate, autonomous routers

Imagine having a massive enterprise application divided into multiple independent submodules (not to be confused with angular modules). I prefer not to overwhelm the routing in a single location and wish for these autonomous modules (non-angular modules) ...

Guide on integrating Vue.js with Sails.js

I attempted to set up Vue.js as the frontend for Sails.js by following the method outlined in this blog post: . However, I encountered issues with the latest version of Vue. I'm unsure why this is happening – can anyone clarify why it's not wor ...

The MaterialTable component is indicating that there is no property called 'tableData' on the IPerson type

Incorporated an editable attribute to my MaterialTable component. Currently looking for a way to retrieve the index of updated or deleted items within the onRowUpdate and onRowDelete methods. To replicate the issue, refer to this minimal sandbox example: ...

Upon the creation of a new Post and attempting to make edits, the field is found to be blank

<template> <div class="card m-3"> <div class="card-body"> <Form method="post" @submit="submitData" :validation-schema="schema" ref="myForm" v-slot="{ errors, ...

An issue has arisen when trying to fetch and parse data using React and JavaScript

I am currently facing some challenges with fetching data from an API and displaying it using React. I have encountered errors and I am struggling with parsing the JSON response from the API. I believe that converting the response into an array may help res ...

The putImageData function claims that the given object is not an ImageData object, but upon inspection in the console, it clearly displays that it is

After using getImageData to store the pixels of an image in a two-dimensional array, I attempted to draw them with putImageData. However, I encountered an error indicating that the first parameter is not of type ImageData. Strangely, when I logged the vari ...

Searching for items in one array within another using Lodash

Hey there! Currently utilizing the lodash library. I'm looking to check if the phone number in receivedMessagesMock matches any of the phone numbers in contactsMocks. If receivedMessagesMock.phone matches contactsMocks.phoneNumbers.value, I want to ...

The inserted button's click event does not trigger the contentEditable DIV

I have a contentEditable DIV that I manage using the directive below: <div class="msg-input-area" [class.focused]="isMsgAreaFocused" contenteditable [contenteditableModel]="msgText" (contenteditableModelChang ...

Is there a way to confirm if I am taking a direct route instead of a detour?

My task seems simple enough: working with Vue3 and the Vue Router, I have a Home.vue component set at the route /, as well as a ProductDetails.vue component at the route /product. I am looking to trigger a specific action when a user navigates to my / rou ...

Using Typescript to add an element to a specific index in an array

Currently, I am engaged in a project using Angular2 and Firebase. My goal is to consolidate all query results under a single key called this.guestPush. Within my project, there is a multiple select element with different user levels - specifically 4, 6, ...