Date Range Picker Integrations

Vue

Use a template ref in a Vue 3 single-file component. Create the picker on mount and release it before the component unmounts.

App source

ReportDates.vue
<script setup>
import { ref, onMounted, onBeforeUnmount } from 'vue';
import DateRangePicker from 'daterangepicker';
import 'daterangepicker/daterangepicker.css';

const input = ref(null);
let picker;

onMounted(() => {
  picker = new DateRangePicker(input.value, { singleCalendar: true });
});

onBeforeUnmount(() => picker?.remove());
</script>

<template>
  <label>Report dates<input ref="input" type="text" /></label>
</template>
main.js
import { createApp } from 'vue';
import ReportDates from './ReportDates.vue';

createApp(ReportDates).mount('#app');
index.html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Report dates</title>
  <link rel="stylesheet" href="../../daterangepicker.css">
  <script type="module" src="../assets/vue.js"></script>
</head>
<body>
  <div id="app"></div>
</body>
</html>
Run this example locally

Serve the website directory over HTTP and open /examples/vue/. To edit the app, change its files in example/integrations/vue and run these commands from example/integrations.

npm ci
npm run build