Posts

Showing posts with the label Vuejs2

Can I Pass Parameters In Computed Properties In Vue.Js

Answer : Most probably you want to use a method <span>{{ fullName('Hi') }}</span> methods: { fullName(salut) { return `${salut} ${this.firstName} ${this.lastName}` } } Longer explanation Technically you can use a computed property with a parameter like this: computed: { fullName() { return salut => `${salut} ${this.firstName} ${this.lastName}` } } (Thanks Unirgy for the base code for this.) The difference between a computed property and a method is that computed properties are cached and change only when their dependencies change. A method will evaluate every time it's called . If you need parameters, there are usually no benefits of using a computed property function over a method in such a case. Though it allows you to have a parametrized getter function bound to the Vue instance, you lose caching so not really any gain there, in fact, you may break reactivity (AFAIU). You can read more about this in Vue documentation htt...

Copy Url To Clipboard Via Button Click In A Vuejs Component

Answer : If you need to use vuejs ref add it as attribute <a :href="link_url" class="text-dark" target="_blank" rel="noopener noreferrer" ref="mylink"> {{ link_name }} </a> and use it in your method in the following way: methods: { copyURL() { var Url = this.$refs.mylink; Url.innerHTML = window.location.href; console.log(Url.innerHTML) Url.select(); document.execCommand("copy"); } } However you should take a look to this link to have a better cross-browsing solution. In this case you don't need the ref attribute. This is the solution in the link adapted to your case: methods: { copyUrl() { const el = document.createElement('textarea'); el.value = this.link_url; el.setAttribute('readonly', ''); el.style.position = 'absolute'; ...

Conditional In Vue.js Dependant On Prop Value?

Answer : Assuming you want to disable anchor tag as in not clickable and look disabled the option is using CSS. isActive should return true by checking prop id. <router-link class="Card__link" v-bind:class="{ disabled: isActive }" :to="{ name: 'Property', params: { id: id }}"> <h1 class="Card__title">{{ title }}</h1> <p class="Card__description">{{ description }}</p> </router-link> <style> .disabled { pointer-events:none; opacity:0.6; } <style> If you want to just disable the navigation , you can use a route guard. beforeEnter: (to, from, next) => { next(false); } The problem is that router-link renders as an html anchor tag, and anchor tags do not support the disabled attribute. However you can add tag="button" to router-link : <router-link :to="myLink" tag="button" :disabled="isDisabled" > V...