Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Armani's avatar
Level 17

Choices js with Vue js

I want to use Choices.js inside Vuejs but I couldn't find a package for it neither a good tutorial about it. specially how get the selected value from it.

0 likes
1 reply
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

To use Choices.js with Vue.js, you can install the Choices.js package via npm and then import it in your Vue component. Here's an example:

  1. Install Choices.js via npm:
npm install choices.js
  1. Import Choices.js in your Vue component:
import Choices from 'choices.js';
  1. In your Vue component's mounted hook, initialize Choices.js on your select element:
mounted() {
  const selectElement = document.querySelector('#my-select');
  const choices = new Choices(selectElement);
}
  1. To get the selected value from Choices.js, you can listen for the change event on the select element and then access the selected value:
mounted() {
  const selectElement = document.querySelector('#my-select');
  const choices = new Choices(selectElement);

  selectElement.addEventListener('change', (event) => {
    const selectedValue = event.target.value;
    console.log(selectedValue);
  });
}

Note that you'll need to replace #my-select with the ID of your select element.

1 like

Please or to participate in this conversation.