What is the difference between v-model and .sync when used on a custom component

For Vue.js 2 both pretty much do the same thing – enable two-way binding, although .sync is more versatile. It was added after v-model was added for components. .sync allows to use v-model logic for more than one prop. Let’s compare: .sync <comp :value.sync=”username” :age.sync=”userAge” /> expands to: <comp :value=”username” :age=”userAge” @update:value=”val => username = … Read more

Vue.js: Data is not updating with state change so the re-render does not happen

NOTE: at the bottom of this answer, see the general point I make about update/reactivity issues with Vue. Now, about the question, based on the code you posted, considering the template: <div v-for=”video in videos” :key=”video.id”> It picks the videos from: data () { return { videos: freeVideo } } Although it initializes from freeVideo, … Read more

Vue js project not loading .env variables

From docs: Note that only NODE_ENV, BASE_URL, and variables that start with VUE_APP_ will be statically embedded into the client bundle with webpack.DefinePlugin. It is to avoid accidentally exposing a private key on the machine that could have the same name. So you need to add VUE_APP_ prefix to your variables.

Vue.js 3 – replace/update reactive object without losing reactivity

Though Boussadjra Brahim’s solution works its not the exact answer to the question. In the sense that reactive data can not be reassigned with = but there is a way to reassign the reactive data. It is Object.assign. Therefore this should work setup(){ const formData = reactive({}) onMounted(() => { fetchData().then((data) => { if (data) … Read more

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