[Vuejs]-Prefill on Vuejs input using js

0👍

if you are using Vuejs. You can give initial values in data function and bind them with input.

In component html

<input id="input-24" v-model="title">

Vue Js:

var vm = new Vue({
  data:function(){
       return {
            title:"Hello World"
       }
   }
});

as per your website. your Input need Focus First

document.getElementById(‘input-24’).focus();
document.getElementById(‘input-24’).value= "aaaaa";

But Focus does not work from Chrome console. The console gets ffocus after each command is run. so the focus will not work for the inputs from console.
but if you want to test this code from console you have to write in different manner as below.

setTimeout(function(){document.getElementById('input-24').focus();
setTimeout(function(){document.getElementById('input-24').value = "Hello world"},2000);
 },5000);

After executing it immediately click anywhere on the page to take focus out of the console. now after 5 seconds the focus will set on the input..

But in script tag of the page it should be :

<script>

(function() {
   document.getElementById('input-24').focus();
   document.getElementById('input-24').value = "Hello world"
})();
</script> 

hope this helps!

Leave a comment