Giter Club home page Giter Club logo

vue-customjs's Introduction

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 = require('vue-customjs');

Or when using ES6

import customjs from 'vue-customjs'

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

  1. 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.add(jsCode);
  1. addUrl(url): This function takes one and only one parameter which is the url;
customjs.addUrl("https:www.cdn.com/library");

The Complete Example in a Vue Component

  • add
<script>
var customjs = require('vue-customjs'); //importing the module into customjs var

export default {
  data(){
    return {
      //nothing to do here
    }
  },
  methods: {
    buttonClick: ()=>{
      var code = "alert('It is snowing')"; // The whole code you want to run
      customjs.add(code); // adding code
    }
  }
}
</script>
  • addUrl
<script>
var customjs = require('vue-customjs'); //importing the module into customjs var

export default {
  data(){
    return {
      //nothing to do here
    }
  },
  created: ()=>{
      customjs.addPath('https:www.cdn.com/library'); //The url of the library you want to add
  }
}
</script>

Thank you. Please report any issues

vue-customjs's People

Contributors

doc-han avatar

Stargazers

Amos Aidoo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.