Farshad
Farshad

Reputation: 2000

how to use a sent variable from php into vue.js

i am already sending a variable from laravel to my vuejs like below : but when i want to use it in a component as an string it gives not defined error my vue component code is like below

 export default {
        props: ['reserve_end'],
        data(){
            return {
                date: '',


            }
        },
}
// the component part
 import VuePersianDatetimePicker from 'vue-persian-datetime-picker'
    Vue.use(VuePersianDatetimePicker, {
        name: 'custom-date-picker',
        props:
            {
                min: //i want to use the reserve_end here as an string


            }
    });

and finally the html markup

                    <custom-date-picker v-model="date"></custom-date-picker>

but in the end it wont load and gives error that reserve_end is not defined i want to know how can i pass this reserve_end to the datepicker as an string here is the devtoll picture of tracing enter image description here

Upvotes: 0

Views: 573

Answers (1)

Benjamin Beganović
Benjamin Beganović

Reputation: 1158

// First component (getting value from Laravel): export default { props: ['reserve_end'] }

Now, in the first component, you should have an access to this.reserve_end.

// template of first component <template> <second-component :date="reserve_end"></second-component> </template>

Let's pass the value to another component, using same technique - props.

// Second component (getting value from first component export default { props: ['date'] }

Now, in the second, component we can:

{{ date }}, to get the date :)

However, don't forget to inspect each component Vue devtools.

Upvotes: 1

Related Questions