chrisgrim
2 weeks ago
103
2
Vue

Question about Javascript ES6 arrow function and plugin

Posted 2 weeks ago by chrisgrim

Hi, I am using the flatpickr plugin and having an issue getting data out of it. In my data config I have

data() {
    return{
                dates: '',
                config: {
                    mode: "range",
                    dateFormat: 'Y-m-d H:i:s',
                                onClose: [function(value){
                        const dateArr = value.map(date => this.formatDate(date, "Y-m-d H:i:s"));
                        console.log(dateArr);
                    }] 

if I run this I get the dates formatted correctly from the dateArr console. However if I try to pass the data then I get an error

onClose: [function(value){
                        const dateArr = value.map(date => this.formatDate(date, "Y-m-d H:i:s"));
                       this.saveDates(dateArr);

because it can't access my data. However if I do the java6 arrow

onClose: [(value) => {
                        const dateArr = value.map(date => this.formatDate(date, "Y-m-d H:i:s"));
                        this.testUpdate(dateArr);
                    }] 

it tells me that this.formatDate is not a function. How do I do both?

Please sign in or create an account to participate in this conversation.