VueJS conditionally add an attribute for an element

In VueJS we can add or remove a DOM element using v-if: <button v-if=”isRequired”>Important Button</button> but is there a way to add / remove attributes of a dom element eg for the following conditionally set the required attribute: Username: <input type=”text” name=”username” required> by something similar to: Username: <input type=”text” name=”username” v-if=”name.required” required> Any ideas? … Read more

What is the difference between the views and components folders in a Vue project?

I just used the command line (CLI) to initialize a Vue.js project. The CLI created a src/components and src/views folder. It has been a few months since I have worked with a Vue project and the folder structure seems new to me. What is the difference between the views and components folders in a Vue … Read more

Vuex – passing multiple parameters to mutation

I am trying to authenticate a user using vuejs and laravel’s passport. I am not able to figure out how to send multiple parameters to the vuex mutation via an action. – store – export default new Vuex.Store({ state: { isAuth: !!localStorage.getItem(‘token’) }, getters: { isLoggedIn(state) { return state.isAuth } }, mutations: { authenticate(token, expiration) … Read more

How to implement debounce in Vue2?

I have a simple input box in a Vue template and I would like to use debounce more or less like this: <input type=”text” v-model=”filterKey” debounce=”500″> However the debounce property has been deprecated in Vue 2. The recommendation only says: “use v-on:input + 3rd party debounce function”. How do you correctly implement it? I’ve tried … Read more

Is there a way to dispatch actions between two namespaced vuex modules?

Is it possible to dispatch an action between namespaced modules? E.g. I have Vuex modules “gameboard” and “notification”. Each are namespaced. I would like to dispatch an action from the gameboard module in the notification module. I thought I could use the module name in the dispatch action name like this: // store/modules/gameboard.js const actions … Read more

How to add external JS scripts to VueJS Components?

I’ve to use two external scripts for the payment gateways. Right now both are put in the index.html file. However, I don’t want to load these files at the beginning itself. The payment gateway is needed only in when user open a specific component (using router-view). Is there anyway to achieve this? Thanks. 17 Answers … Read more