Posts

Showing posts with the label Vue.js 3

Donate

Set Focus Or Auto Focus Input Control Using Inserted And Directive Not Working In Vue.js 3

Hello, Given the input element with an autofocus directive that on page load, this control get's focused right away. <input v-autofocus :class= "{ 'error' : empname.length > 22 }" /> The code to automatically focus the control is shown below using the inserted() method. directives:{ autofocus: { inserted(el){ el.focus(); } } } For some reasons the code above does not work in Vue.js 3x. After reading the docs, the solution that work was to use mounted() function instead of inserted() method if you're using Vue.js 3x. directives:{ autofocus: { mounted(el){ el.focus(); } } } Cheers!

Async Fetch Not Working When Retrieving Data From JSONPlaceholder API In JavaScript And Vue.JS

Image
Hello, I was trying to retrieve data from a Free Fake API website called JSON Placheholder using the code below which using asynchronous behavior. However, this does'nt return data after all. async getDataAsync(){ try { let response = await fetch( 'http://jsonplaceholder.typicode.com/todos' ); console.log(response.data); this .todos = response.data; } catch (error) { console.log(error); } After doing some research, I came up with a solution and replace the code above using JavaScript Promise as a means to retrieve data from the Fake API website in an asynchronous manner. await fetch( 'http://jsonplaceholder.typicode.com/todos' ) .then(response => response.json() ) .then(data => { this .todos = data; }) . catch (error => { return Promise.reject(error); }); } Cheers!

Axios.Get HTTP Client Not Returning Data From API In Vue.js

Image
Good day! I was following a tutorial on how to create a simple tutorial on how to create a Todo List project that retrieves data from a dummy API website in Youtube using the Axios HTTP Client Library. However fetching the API data from jsonplaceholder.typicode.com using Axios get() method does'nt return any results and the browser just rendered the white screen of death. After reading through my code thoroughly, I noticed that I have misplaced the created event inside the methods property which is the culprit of the issue. export default { name: 'home' , components: { Todos, Header, AddTodo }, data(){ return { todos:[], } }, methods:{ deleteTodo(id){ console.log(id); axios. delete (`https: //jsonplaceholder.typicode.com/todos/${id}`) .then(res => { this .todos = this .todos.filter(todo => todo.id !== id) return res }) . catch (error => {

Donate