Vue template or render function not defined yet I am using neither?

In my case, I was getting the error because I upgraded from Laravel Mix Version 2 to 5. In Laravel Mix Version 2, you import vue components as follows: Vue.component( ‘example-component’, require(‘./components/ExampleComponent.vue’) ); In Laravel Mix Version 5, you have to import your components as follows: import ExampleComponent from ‘./components/ExampleComponent.vue’; Vue.component(‘example-component’, ExampleComponent); Here is the … Read more

Vue v-on:click does not work on component

If you want to listen to a native event on the root element of a component, you have to use the .native modifier for v-on, like following: <template> <div id=”app”> <test v-on:click.native=”testFunction”></test> </div> </template> or in shorthand, as suggested in comment, you can as well do: <template> <div id=”app”> <test @click.native=”testFunction”></test> </div> </template> Reference to … Read more

Apply global variable to Vuejs

Just Adding Instance Properties For example, all components can access a global appName, you just write one line code: Vue.prototype.$appName=”My App” or in vue3 app.config.globalProperties.$http = axios.create({ /* … */ }) $ isn’t magic, it’s a convention Vue uses for properties that are available to all instances. Alternatively, you can write a plugin that includes … Read more

Is there any way to ‘watch’ for localstorage in Vuejs?

Sure thing! The best practice in my opinion is to use the getter / setter syntax to wrap the localstorage in. Here is a working example: HTML: <div id=”app”> {{token}} <button @click=”token++”> + </button> </div> JS: new Vue({ el: ‘#app’, data: function() { return { get token() { return localStorage.getItem(‘token’) || 0; }, set token(value) … Read more

Passing props dynamically to dynamic component in VueJS

To pass props dynamically, you can add the v-bind directive to your dynamic component and pass an object containing your prop names and values: So your dynamic component would look like this: <component :is=”currentComponent” v-bind=”currentProperties”></component> And in your Vue instance, currentProperties can change based on the current component: data: function () { return { currentComponent: … Read more