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

Is it possible to change props value from method in Vue component?

What you are doing will throw a warning in Vue (in the console). [Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop’s value. Prop being mutated: “propRoomSelected” The value will actually change inside the component, … Read more

Can we make vue.js application without .vue extension component and webpack?

As stated in this jsFiddle: http://jsfiddle.net/posva/wtpuevc6/ , you have no obligation to use webpack or .vue files. The code below is not from me and all credit goes to this jsFiddle creator: Create an index.html file: <script src=”https://npmcdn.com/vue/dist/vue.js”></script> <script src=”https://npmcdn.com/vue-router/dist/vue-router.js”></script> <script src=”/js/Home.js”></script> <script src=”/js/Foo.js”></script> <script src=”/js/router.js”></script> <script src=”/js/index.js”></script> <div id=”app”> <router-link to=”https://stackoverflow.com/”>/home</router-link> <router-link to=”/foo”>/foo</router-link> <router-view></router-view> … Read more

Property ‘XXX’ does not exist on type ‘CombinedVueInstance’

As mentioned in the Typescript Support section of the Vue documentation: Because of the circular nature of Vue’s declaration files, TypeScript may have difficulties inferring the types of certain methods. For this reason, you may need to annotate the return type on methods like render and those in computed. In your case, you should change … Read more

How to make dynamic routes on the vue router?

I suppose getDetailMenu is calling API method to get listMenu. You can create route dynamically using addRoutes method Pseudo code created() { this.getDetailMenu(this.$route.path) .then((listMenu) => { // you need to return listMenu from getDetailMenu listMenu.forEach((item, index) => createAndAppendRoute(item, index)) }) }, methods: { createAndAppendRoute: (item, index) => { console.log(item, index) // Base on your data, … Read more

Add global variable in Vue.js 3

The most direct replacement is app.config.globalProperties. See: https://vuejs.org/api/application.html#app-config-globalproperties So: Vue.prototype.$myGlobalVariable = globalVariable becomes: const app = createApp(RootComponent) app.config.globalProperties.$myGlobalVariable = globalVariable This is scoped to a particular application rather than being global as it was with Vue.prototype. This is by design, all ‘global’ configuration options are now scoped to an application. The relevant RFC is here: … Read more