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

138
Vistas
Bind my vuejs model data to the object that will post

I am tasked with binding the data from my input into my vuejs model-so that when the text change happens, it updates in the model. I tried putting the.UnitName inside the model, but that doesnt work either. Can someone give me some insight on how to do this.

  new Vue({
  el: "#app",
  data: {
  UnitName:'',
  },
  methods: {
    toggle: function(todo){
        todo.done = !todo.done
    }
  }
})

$( document ).ready(function() {
 $("#myMagic").click(function(){
alert("test");
$.ajax({
  url: "",
  type: "POST",
  data: {
    "UnitName": "bobby",

  },
  headers: {
     "content-type": "application/x-www-form-urlencoded"
  },


  })
  
})

});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css">

        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">

        <script src="https://s.brightspace.com/lib/jquery/2.2.4/jquery.min.js" role="presentation"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>


<body>
<div id="app" class="container">



                Title <input v-model="UnitName">{{UnitName}}<br><br>
   

<button class="btn btn-primary" id="myMagic">Create</button>

</div>

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

0

Your data must be a function that returns an object, then you just need to bind the onclick of your button. Remember to preventDefault on the form submission, so your page doesn't reload.

new Vue({
  el: "#app",
  data(){
  return {
    UnitName:''
    }
  },
  methods: {
    toggle: function(todo){
        todo.done = !todo.done
    },
    onSubmit(event){
      event.preventDefault();
      alert(this.UnitName);
      $.ajax({
        url: "",
        type: "POST",
        data: {
          "UnitName": this.UnitName,

        },
        headers: {
           "content-type": "application/x-www-form-urlencoded"
        }
      })
    }
  }  
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css">

        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">

        <script src="https://s.brightspace.com/lib/jquery/2.2.4/jquery.min.js" role="presentation"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>


<body>
<div id="app" class="container">



                Title <input v-model="UnitName">{{UnitName}}<br><br>
   

<button class="btn btn-primary" id="myMagic" @click="onSubmit">Create</button>

</div>

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