Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

200
Vistas
change treeselect vue value from js

I am trying to make a school project in normal js but I required a tree view select with multiple layers so I ended up after lots of searching finding this.

It works great but the only thing I can't seem to figure out is how can I change its value. This is the code I am using to implement it:

<body>
    <div id="app">
      <treeselect v-model="value" @input="onInput" :multiple="true" :options="options" />
    </div>
  </body>
  <script>
    // register the component
    Vue.component('treeselect', VueTreeselect.Treeselect)

    new Vue({
      el: '#app',
      data: {
        // define the default value
        value: null,
        // define options
        options: [ {
          id: 'a',
          label: 'a',
          children: [ {
            id: 'aa',
            label: 'aa',
          }, {
            id: 'ab',
            label: 'ab',
          } ],
        }, {
          id: 'b',
          label: 'b',
        }, {
          id: 'c',
          label: 'c',
        } ],
      },
            methods: {
                onInput(value, id) {
                    console.log(value, id);//I use this to get the value selected
                }
            }
        });
  </script>

I have tried to change the treeselect value by giving it an ID and using basic js to change it but that didn't work. I have also thought that giving the value a variable and changing that variable later would do the trick but nothing worked.

If someone has any suggestions or even a better more simpler way to add a tree view dropdown please let me know.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I made a makeshift solution that I'll be using for the time being. I added all the content of the Vue component inside a function with a variable value and made the function replace the #app content with the new value.

create_treeselect(null);

function create_treeselect(value){
document.getElementById("app").innerHTML = '<treeselect v-model="value" @input="onInput" :multiple="true" :options="options" />';
 Vue.component('treeselect', VueTreeselect.Treeselect)
    new Vue({
      el: '#app',
      data: {
        // define the default value
        value: value,
        // define options
        options: [ {
          id: 'a',
          label: 'a',
          children: [ {
            id: 'aa',
            label: 'aa',
          }, {
            id: 'ab',
            label: 'ab',
          } ],
        }, {
          id: 'b',
          label: 'b',
        }, {
          id: 'c',
          label: 'c',
        } ],
      },
            methods: {
                onInput(value, id) {
                    console.log(value, id);//I use this to get the value selected
                }
            }
        });
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda