1. vue-add-globals
Add vue instance methods, directives, mixins and properties
vue-add-globals
Package: vue-add-globals
Created by: eddyerburgh
Last modified: Tue, 28 Jun 2022 18:56:32 GMT
Version: 2.0.1
License: MIT
Downloads: 4,831
Repository: https://github.com/eddyerburgh/vue-add-instance-method

Install

npm install vue-add-globals
yarn add vue-add-globals

vue-add-globals

Add globals to Vue. Use it in tests to mock global methods and properties.

Example

Adding a property and method to Vue

 import addGlobals from 'vue-add-globals'
import Vue from 'vue'

const $someMethod = () => ({})
const someProp = 'prop'
addGlobals(Vue, {
  $someMethod: $someMethod,
  someProp: someProp
})
const Ctor = Vue.extend(TestComponent)
const vm = new Ctor().$mount()

t.is(vm.$someMethod, $someMethod)
t.is(vm.someProp, someProp)

Installation

 npm install --save-dev vue-add-globals

Usage

  • Import 'vue-add-globals'
  • Call it with object of global properties to add
 import addGlobals from 'vue-add-globals'

addGlobals(Vue, { $mockedMethod: mockedMethod })

You can keep the global Vue class clean by using Vue.extend():

 import addGlobals from 'vue-add-globals'
import Vue from 'vue'

const freshVue = Vue.extend()

addGlobals(freshVue, { $mockedMethod: mockedMethod })

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin