Transmit data from a child component to a Vue JS page through props, and trigger the @blur/@focus function to access the prop from the parent component

Seeking guidance on working with props in Vue JS. As a newcomer to Vue, I hope that my question is clear.

I've included my code snippet below, but it isn't functioning correctly due to missing Vue files.

In my attempt to use a prop created in the DiscountComponentShared.vue file, I want to utilize this prop within CartPage.vue to bind a 'disabled' class if the promo code input is clicked. My preference is to use @blur and @focus for binding my logic, but I'm uncertain how to do so. Currently, I have set it up with an @click event. When a user clicks on the input, it will display as disabled and apply the 'disabled' class.

//CartPage.vue
<input type="text" placeholder="Enter promo code here" @click="togglePromoCodeInput()" />

<app-one-discount :class="{'moreInfo': showMoreInfo, 'disabled': isDisabled}" :discount-list-disabled="isDisabled">
  <template slot="moreInfoText">
      Minimum purchase of $5. Valid for 3 orders.
      Valid until 24 August 2018 Minimum purchase of $5.
  </template>

  <button class="moreInfoBtn font-italic font-12 text-teal mt-15" @click="toggleMoreInfo" slot="moreInfoBtn">{{ moreInfoBtn }}</button>
</app-one-discount>

<script lang="ts">
  import {
    Vue,
    Component,
    Prop
  } from 'vue-property-decorator';
  import OneDiscount from '../../components/shared/DiscountComponentShared.vue';

  @Component({
    components: {
      appOneDiscount: OneDiscount
    }
  })

  export default class CartPage extends Vue {
    isDisabled: boolean = true;

    togglePromoCodeInput() {
      this.isDisabled = !this.isDisabled;
    }
  }
</script>

//DiscountComponentShared.vue
<template>
    <div class="oneDiscount d-flex justify-content-between">
        <div class="discountAmountBox d-flex align-items-center justify-content-center">
            <p class="text-teal font-20">$50 OFF</p>
        </div>

        <div class="discountInfo d-flex align-items-center flex-wrap">
            <div>
                <p class="text-black font-18 font-weight-bold mb-5">Discount Name</p>

                <div class="discountText text-black font-12">
                        <slot name="moreInfoText"></slot>
                </div>

                <slot name="moreInfoBtn"></slot>
            </div>
        </div>
    </div>
</template>

<script lang="ts">
  import {
    Vue,
    Component
  } from 'vue-property-decorator';

  @Component
  export default class DiscountComponentShared extends Vue {
    props!: {
      discountListDisabled: {
        type: Boolean,
        default: false
      }
    }
  }
</script>

Answer №1

I successfully resolved my own issue by utilizing the vue-property-decorator and calling props as @prop()

In addition, I incorporated @focus and @blur events to manage the discDisabled data property.

Many thanks to all who attempted to assist me!

Hopefully, this solution will be beneficial to someone in the future.

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

Attempting to invoke a promise within a function yields an error message stating that it lacks call signatures

Recently, I came across this interesting class: export class ExponentialBackoffUtils { public static retry(promise: Promise<any>, maxRetries: number, onRetry?: Function) { function waitFor(milliseconds: number) { return new Pr ...

Sort the observable data by a value returned from an API request

I am completely new to using RxJS and any assistance offered would be greatly appreciated! Within my component's HTML template, I am looking to create a radio button list. The values for this list are fetched from an observable using the async pipe. ...

Setting the default value for Angular Material's select component (mat-select)

Many inquiries are focused on setting a default value to display in a "Select" control. In this particular case regarding Angular 8 template driven forms, the issue lies in the inability to show the default value in the mat-select when the button is clicke ...

The declaration file for the module 'tailwind-scrollbar' could not be located

Currently, I am in the process of utilizing Tailwind packages for a Next.js application, however, I have encountered an issue that has proved to be quite challenging to resolve. Every time I attempt to add a "require" statement to my tailwind.config.js fil ...

"Mastering the Composition API in Vue 3: A guide to defining props within the setup() method

I created a custom "loading state" mixin specifically for Vue 2: export default { props: { loading: { type: Boolean, default: false }, }, data () { return { innerLoading: false, } }, mounted () { this.innerLo ...

Exploring the best way to access ViewContainerRef: ViewChild vs Directive

While researching, I came across a recommendation in the Angular Docs that suggests using a directive to access the ViewContainerRef for creating dynamic components. Here is an example of such a directive: import { Directive, ViewContainerRef } from &apos ...

Delay the v-alert display after an item is added to the array basket using setTimeout

here is my custom rightTableMenu template <template> <div> <h1 align="center">{{ title }}</h1> <v-alert type="info" icon="mdi-emoticon-sad" v-if="basketStatus"> Empty Basket, please add some to basket < ...

What are the steps to resolve the issue of assigning void type to type ((event: MouseEvent<HTMLDivElement, MouseEvent>) => void) | undefined in a react application?

I'm trying to update the state isOpen to true or false when clicking on a div element, but I keep getting an error with the following code: function Parent() { const [isOpen, setIsOpen] = React.useState(false); return ( <Wrapper> ...

Unfulfilled expectation of a promise within an array slipping through the cracks of a for loop

I have a function that generates a Promise. Afterward, I have another function that constructs an array of these promises for future utilization. It is important to note that I do not want to execute the promises within the array building function since so ...

The response from an Axios post request is in HTML format

Hello everyone, I am currently using the following dependencies in my project: "laravel/framework": "^6.2", "axios": "^0.19", "vue": "^2.5.17". I have encountered an issue with axios requests. When I use axios.put, the response.data is correct (response. ...

Is Typescript familiar with the import -> require syntax, but unfamiliar with the require -> import syntax?

My code includes a simple file that utilizes the ES6 module loader: 1.ts import {foo} from "./2" foo('hello'); 2.ts function foo (a){console.log(a);}; export {foo} When the tsconfig is configured as follows: "module": "commonjs", We can o ...

Downloading PDF files on IOS while using Angular often results in the PDF opening in the same

I'm currently utilizing file-saver within my Angular application to retrieve a PDF generated from the backend. The library functions smoothly on desktop and Android devices, but I'm encountering issues with downloading files on iOS. Contrary to w ...

Using Visual Studio Code Build Tasks in Harmony

The documentation for Visual Studio Code includes examples of tasks.json configurations that allow for either typescript compilation or markdown compilation, but does not provide clear instructions on how to achieve both simultaneously. Is there a way to ...

Utilize the filtering feature within the Vue select module

I'm struggling to get the select filter to work properly in my Quasar application. When I open the select, there is no list displayed and no value gets selected. Can someone help me understand why it's not working? <q-select v-mo ...

Empty Angular-chart.js Container

How can I resolve the issue of getting a blank div and no output while trying to display a chart where the options, labels, and other data are initialized in the TypeScript controller and then used on the HTML page? I added the angular-chart.js library us ...

Locate the closest Vue parent component containing the template reference (Vue 3)

After a Vue template ref is initialized, my goal is to identify the closest parent Vue component. To make this functionality versatile and applicable to any template ref, I have encapsulated it within a composition function (although that's merely an ...

Optimizing Node.js and Express routes by separating them into individual files: a

When using Express in a Node project along with Typescript, what are the best practices for express.Router? For instance, it is recommended to follow a directory structure like this: |directory_name ---server.js |--node_modules |--routes ---in ...

Updating item information within an array in Vue.js

I'm currently working on integrating an edit feature into a task application using Vue JS. My issue lies in the fact that I have a click event assigned to the edit button - @click="editShow" which displays input fields for editing all items instead ...

Transferring chosen string data from <childComponent1/> to <childComponent2/> in vue.js

In my code, I have a block of Vue.js code that involves a <select> element within the <oneChildComponent />: new Vue({ template:' <select v-model="selectedOption" @change="handleChange"> < ...

Transform PDF files into PNG format directly in your web browser

I am currently utilizing Vue.js and attempting to convert a PDF file to PNG or another image format directly within the browser. My current setup involves reading the PDF from a URL using PDF.js along with the Vue.js component pdfvuer. let instance = this ...