How to make dynamic routes on the vue router?

I suppose getDetailMenu is calling API method to get listMenu. You can create route dynamically using addRoutes method Pseudo code created() { this.getDetailMenu(this.$route.path) .then((listMenu) => { // you need to return listMenu from getDetailMenu listMenu.forEach((item, index) => createAndAppendRoute(item, index)) }) }, methods: { createAndAppendRoute: (item, index) => { console.log(item, index) // Base on your data, … Read more

Vue 3: Is getCurrentInstance() deprecated?

getCurrentInstance() was removed from the Vue 3 docs because it’s an internal API: Because the instance is an internal instance that exposes non-public APIs. Anything you use from that instance can technically break between any release types, since they are not subject to semver constraints. getCurrentInstance() was originally documented in 4-Oct-2020, but that was later … Read more

vuetify icon not showing

With Vue CLI 3 we have no index.html in the src folder so alternatively you can npm install –save material-design-icons-iconfont and import it in the main.js file import ‘material-design-icons-iconfont/dist/material-design-icons.css’

Vue 3 Vite – dynamic image src

Update 2022: Vite 3.0.9 + Vue 3.2.38 Solutions for dynamic src binding: 1. With static URL <script setup> import imageUrl from ‘@/assets/images/logo.svg’ // => or relative path </script> <template> <img :src=”imageUrl” alt=”img” /> </template> 2. With dynamic URL & relative path <script setup> const imageUrl = new URL(`./dir/${name}.png`, import.meta.url).href </script> <template> <img :src=”imageUrl” alt=”img” /> … Read more

Difference between v-model and v-bind on Vue.js?

From here – Remember: <input v-model=”something”> is essentially the same as: <input v-bind:value=”something” v-on:input=”something = $event.target.value” > or (shorthand syntax): <input :value=”something” @input=”something = $event.target.value” > So v-model is a two-way binding for form inputs. It combines v-bind, which brings a js value into the markup and v-on:input to update the js value. The js … Read more

What is nextTick and what does it do in Vue.js?

It’s all about Timing nextTick allows you to execute code after you have changed some data and Vue.js has updated the virtual DOM based on your data change, but before the browser has rendered that change on the page. Normally, devs use the native JavaScript function setTimeout to achieve similar behavior, but using setTimeout relinquishes … Read more

Passing event and argument to v-on in Vue.js

If you want to access event object as well as data passed, you have to pass event and ticket.id both as parameters, like following: HTML <input type=”number” v-on:input=”addToCart($event, ticket.id)” min=”0″ placeholder=”0″> Javascript methods: { addToCart: function (event, id) { // use event here as well as id console.log(‘In addToCart’) console.log(id) } } See working fiddle: … Read more

Vue.js—Difference between v-model and v-bind

From here – Remember: <input v-model=”something”> is essentially the same as: <input v-bind:value=”something” v-on:input=”something = $event.target.value” > or (shorthand syntax): <input :value=”something” @input=”something = $event.target.value” > So v-model is a two-way binding for form inputs. It combines v-bind, which brings a js value into the markup and v-on:input to update the js value. The js … Read more