Does Vue.js have a built in way to add a copy of a persistent object to a repeated array

See this issue on GitHub. Shallow Clone I was using jQuery’s $.extend until Evan You pointed out there is an undocumented built it extend function Vue.util.extend that does a shallow clone. So what you could use is: addItem: function(e) { e.preventDefault(); this.items.push(Vue.util.extend({}, this.newItem)); } See the updated Fiddle. Deep Clone When doing a shallow clone … Read more

How to pass an object as props with vue router?

It can work by using props’s Function mode and params Vue 2 demo: https://jsfiddle.net/hacg6ody/ when adding routes, use props’s Function mode so that it has a default property user and it will add route.params as props. { path: ‘/create’, name: ‘create’, component: CreateComponent, props: (route) => ({ user: userData, …route.params }) } params passed in … Read more

Vue.js – Add class to clicked button

Try to add another data object property called currentIndex and update it to the clicked button index : // DATA data() { return { currentIndex:-1, isActive: false, … inside the template bind the class as follows :class=”{buttonActive : (index==currentIndex) }”: <div class=”buttonBrand”> <button v-for=”(element, index) in brand” :key=”index” :class=”{buttonActive : (index==currentIndex) }” @click=”changeBrand(index)”> <img v-bind:src=”https://stackoverflow.com/questions/57742076/element.imageBrand” … Read more

How to use components in v-html

Pretty sure Vuejs makes it very hard to directly use external html. v-html will simply replace the html content and therefore will not execute any directive. The purpose of it is to avoid XSS attacks as documented here: https://v2.vuejs.org/v2/guide/syntax.html#Raw-HTML Dynamically rendering arbitrary HTML on your website can be very dangerous because it can easily lead … Read more