How to put class=”active” to first element in vuejs for loop

const TextComponent = { template: ` <p>{{ text }}</p> `, props: [‘text’], }; new Vue({ components: { TextComponent, }, template: ` <div> <text-component v-for=”(item, index) in items” :class=”{ ‘active’: index === 0 }” :text=”item.text”> </text-component> </div> `, data: { items: [ { text: ‘Foo’ }, { text: ‘Bar’ }, { text: ‘Baz’ }, ], }, … Read more

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

Copy text to clipboard: Cannot read properties of undefined reading ‘writeText’

The use of navigator.clipboard requires a secure origin. So if your dev environment is being served over HTTP, then the clipboard method won’t be available. According to MDN Clipboard docs This feature is available only in secure contexts (HTTPS), in some or all supporting browsers. Maybe you could check if this method is available with … Read more