0

I'm currently using a vue datepicker which, when a date is selected, shows pickedValue as the value for the selected date in vue developer tools:

<div v-cloak v-if="isScheduledTask">
            <datepicker value="" name="pickedValue" id="pickedValue" ></datepicker>
</div>

Trying to set the pickedValue to a variable in my data return (i need the picked value to be submitted with other data here) as a $ref is breaking the page. If I change this to just datepicker.pickedValue then it's undefined. What am I doing wrong here?

data() {
    return {
       pickedValue: this.$refs.datepicker.pickedValue
    }
 }

2 Answers 2

2

It's very bad pattern, but you have no choice working with library that does not emit ANY events.

DON'T DO IT EVER AGAIN!!!

<datepicker ref="datepicker" @click.native="method"></datepicker>
data() {
  return {
    value: ''
  }
},
methods: {
  method() {
    this.value = this.$refs.datepicker.pickedValue
  },
},
Sign up to request clarification or add additional context in comments.

Comments

1

Try to use v-model directive to bind your datepicker to that data property pickedValue as follows :

<div v-cloak v-if="isScheduledTask">
  <datepicker value="" name="pickedValue" v-model="pickedValue" ></datepicker>
</div>

script :

data() {
    return {
       pickedValue: ''
    }
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.