简体   繁体   中英

How to use external JavaScript libraries

I am wanting to use the CodeMirror addon called autorefresh.js , but I am not sure how to use it just by looking at the source code. It's just method nested inside brackets and I couldn't find any examples online.

How do I call/use these methods provided?

Refer to the documentation .

Basic Usage The easiest way to use CodeMirror is to simply load the script and style sheet found under lib/ in the distribution, plus a mode script from one of the mode/ directories. For example:

(Alternatively, use a module loader. More about that later.)

Having done this, an editor instance can be created like this:

var myCodeMirror = CodeMirror(document.body); The editor will be appended to the document body, will start empty, and will use the mode that we loaded. To have more control over the new editor, a configuration object can be passed to CodeMirror as a second argument:

var myCodeMirror = CodeMirror(document.body, { value: "function myScript(){return 100;}\\n", mode: "javascript" });

...

You link opens up a new tab in my browser and I see many lines of code. Are you going to use it in some html file? Why don't you copy and paste the lines in your editor, save it and link it with <script type="text/javascript" src="yourfile.js"></script> (assuming your need it for your html file)

You can install it in your project using NPM . For reference : https://www.npmjs.com/package/codemirror

Download codemirror and store it in lib.The easiest way to use CodeMirror is to simply load the script and style sheet found under lib/ in the distribution, plus a mode script from one of the mode/ directories. For example:

<script src="lib/codemirror.js"></script>
<link rel="stylesheet" href="lib/codemirror.css">
 <script src="mode/javascript/javascript.js"></script>

Or if you are using Node.js you can use node package manager (npm) to add the external js. just type

  npm install codemirror

Please refer to https://www.npmjs.com/package/codemirror

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM