How to focus on load with VueJS?
If I use jquery, all I have to do is:
$(document).ready(function() { $('#username').focus(); });
Is there a vue-way or not?
You can create a custom directive for it:
// Register a global custom directive called v-focus Vue.directive('focus', { // When the bound element is inserted into the DOM... inserted: function (el) { // Focus the element el.focus() } })
And then use it like this:
<input v-focus>
Full example from the docs: https://vuejs.org/v2/guide/custom-directive.html
Directive documents: https://vuejs.org/v2/api/#Vue-directive
Source: https://habr.com/ru/post/1261768/More articles:Reducing ASP.NET MVC 5 from .NET 4.5 to 4.0 - c #Java reflection - getting fields from a subclass as well as a superclass - javaCannot load files larger than 50 KB using AJAX - javascriptmvc version 5 for mvc 4 - c #How to call vue method only once, and not every time - javascriptDowngrade / convert mvc 4 to mvc 3 - asp.netSELECT using BETWEEN MYSQL and a PHP variable - phpPHP works simultaneously with several scripts - phpPHP ssh2_tunnel: Use ssh proxy? - phpNeed to find the IP address of a network interface on Ubuntu using PHP - linuxAll Articles