Importing javascript file for use within vue component

Include an external JavaScript file Try including your (external) JavaScript into the mounted hook of your Vue component. <script> export default { mounted() { const plugin = document.createElement(“script”); plugin.setAttribute( “src”, “//api.myplugincom/widget/mykey.js” ); plugin.async = true; document.head.appendChild(plugin); } }; </script> Reference: How to include a tag on a Vue component Import a local JavaScript file In … Read more

Check history previous location before goBack() react router v4

While navigating though the Link component or even though history.push, you could pass the current location to another Route component like <Link to={{pathname: ‘/graph/1’, state: { from: this.props.location.pathname }}} /> or history.push({ pathname: ‘/graph/1’, state: { from: this.props.location.pathname } }) and then you could just get this location in your Component like this.props.location.state && this.props.location.state.from … Read more

Is Babel a compiler or transpiler?

The definitions of “transpiler” and “compiler” are blurry. Both of them do translate a program from one language to another language while keeping the behaviour. We usually name it a “compiler” when it produces an executable binary. However, binary is just another language, which can be interpreted by a CPU. Every program is “executable” on … Read more

ES6 modules: imported constants are undefined at first; they become available later

As suggested in the comments, the answer here are circular dependencies. There is actually no circular dependency present in the code provided in the question (because it’s just a simplified snippet of code) but the symptoms are very clear. The simplest example of a circular dependency is when file A imports file B and file … Read more

What is the meaning of “…args” (three dots) in a function definition?

With respect to (…args) =>, …args is a rest parameter. It always has to be the last entry in the parameter list and it will be assigned an array that contains all arguments that haven’t been assigned to previous parameters. It’s basically the replacement for the arguments object. Instead of writing function max() { var … Read more

React statics with ES6 classes

statics only works with React.createClass. Simply declare the method as a static class method: class SomeComponent extends React.Component { static someMethod() { //… } render() { // … } } Regarding React.statics = { … } You are literally creating a statics property on the React object. That property does not magically extend your component.