view package at https://www.npmjs.com/package/vue-customjs
vue-customjs
A simple package to enable users to add custom JavaScript to a vue Component or project
Initialisation
This is done by a simple require.
var customjs = ;
Or when using ES6
Available functions/Methods
Below are the available functions or methods for adding a custom javascript code to your vue component.
- add: Used to add custom JavaScript which is in the form of a string.
- addUrl: Used to add custom JavaScript from an external link, mostly libraries.
Examples
- add(jsCode): The add function takes only one parameter which is the JavaScript code(jsCode) in a form of a string.
Note:
Code added using this function is registered to the global scope. Meaning it not just called when the function in which it is defined is called. Hence you can register new Javascript codes to be added to the DOM. Code added using this function get to run always.
var jsCode = `var a = 'I am a custom JavaScript code';alert(a);`;customjs;
- addUrl(url): This function takes one and only one parameter which is the url;
customjs;
The Complete Example in a Vue Component
- add
- addUrl