Skip to main content

Mixins in vue js:

Mixins are a flexible way to distribute reusable functionalities for Vue components.
A mixin object can contain any component options.
When a component uses a mixin, all options in the mixin will be “mixed” into the component’s own options.


Let suppose i want to implement enable/hide loader methods in whole project, but i don't want to create methods for enable/hide loader in every vue instance.

Then Mixins is good idea over here. Please check below examples for more details:

mixins:
export const myMixin = {
    data() {
        return {
            isLoading: false,
        }
    },
    methods: {
        enableLoader() {
            this.isLoading = true;
        },
        hideLoader() {
            this.isLoading = false;
        }
    }
};

Vue instance:
 import { myMixin } from '../mixins';
 new Vue({
  mixins: [myMixin],
  methods: {
   method1() {
  
    // Here you can use the methods from the Mixins, You can add more global methods to mixin and can use over different vue instance
    this.enableLoader();
   }
  }

 });

Comments

Popular posts from this blog

As a symfony developer what you should take care when symfony standard edition is legacy:

Now  symfony standard edition is legacy . So no need to worry much just go threw article and understand whats new in symfony 4 if standard edition is legacy now. This is the main difference in Symfony 4 from symfony 2 and symfony 3 . Older symfony versions provide by default doctrine, twig, form, validation, profiler, annotations and many other components. But some time user do not want to use it. Suppose what if user do not want to doctrine or twig? Still he has doctrine and twig in his dependency. That makes symfony heavy framework. When starting a new project developers do not like to assemble things manually. So symfony 2 and 3 provides standard edition for developers to start a big project. But was hard to scale down project and decrease dependency if user do not require some packages. Symfony 2 and 3  are big success and in years developers are now aware with composer and dependency injection. So adding/removing a new package is not a big deal. So symfony chose...

3 Node.js Alternatives To WordPress

3 Node.js Alternatives To WordPress As compare to WordPress there is alternative option like Node.js. There are many various latest challengers that have large communities, support themes, plugins and are easy to install on your own server. Here are 3 you might want to checkout. KeystoneJS KeystoneJS is a content management system and framework to build server applications that interact with a database. It is based on the Express framework for Node.js and uses MongoDB for data storage. It represents a CMS alternative for web developers who want to build a data-driven website but don’t want to get into the PHP platform or large systems like WordPress. EnduroJS Enduro.js offers a fast and easy way to build your project, beautiful and simple admin UI and integrated tools to build everything on the server. It works without a database, instead relying on a system of flat files that can be opened directly in a text editor. It is easy to install and can be deployed via Git. ...

AngularJs

What is AngularJS? Angular.JS is a JavaScript framework created by Google. It is most commonly used in web and mobile app development. AngularJS is a structural framework for dynamic web applications. Features:                 DEVELOP ACROSS ALL PLATFORMS: Learn one way to build applications with Angular and reuse code and abilities to build applications for any deployment target. For web, mobile web, native mobile and native desktop.                 SPEED & PERFORMANCE: Achieve the maximum speed possible on the Web Platform, and take it further, via Web Workers and server-side rendering.                 INCREDIBLE TOOLING: Build features quickly with simple, declarative templates. Extend the template language with your own components and use a wid...