Introduction to the method for correctly introducing the JS library in the Vue framework, vuejs
This article mainly introduces the relevant content about correctly introducing the JS library in the Vue framework, and shares it for your reference. I will not talk about it here. Let's take a look at the detailed introduction:
Error example
Global VARIABLE METHOD
The most unreliable way is to put the imported database under the window object of all variables:
// entry.js:window._ = require('
to achieve the same effect as before.ModuleExcellent webpack know how to use the various formats of the JavaScript module, the most famous of the two are:
ES2015 import Statements
CommonJS require() Statements
We can test the modules of these formats by installing and importing Lodash.npm install lodash --save// src/app.jsimport {groupBy} from ‘lodash/collection‘const people = [{ manager
copied.var $ = require('jquery')var o1 = { a : 1, b : { c : 2 } }var o2 = $.extend({}, o1)console.log(o1.b === o2.b) // trueconsole.log(o1.a === o1.a) // false6. _.clone in Lodash ()The use of structured copy algorithms. Support Copy Arrays,array Buffers,booleans, data objects, maps,Numbers, Object objects, regexes, sets, strings, symbols, and typedArrays. An arguments enumerable property of an object is copied as a normal object.Returns an empty obj
getFilters() returned list is not in the order of set-indeed, this is the HashMap characteristic of disorder. But for simple conditions, whichever comes first, the result is the same. But for some compound condition judgment, may have the influence.
If you really need to, you can use array instead of map to solve the order problem, but this will reduce the search efficiency (linear lookup). If you also want to solve the problem of search efficiency, you can use array + map to handle. There's
1. Create a new folder named Project name--myapp and open the MyApp folder.
mkdir Webpack-demo CD Webpack-demo
2. Open a command-line window in./myapp, enter NPM init , Initialize NPM, and press ENTER to use the default configuration.
At this point, the Package.json file is generated in./myapp.
3. Install Webpack and webpack-cli locally (this tool is used to run Webpack on the command line) "1"
NPM Install Webpack webpack-cli--save-dev
At this point, the Package.json content is:
./myapp is:
tool library that allows us to manipulate data such as String, array, collections, object, etc.
Lodash a fork underscore library, the final performance is several times higher than underscore, and provides a good API underscore not ... Why say Lodash than underscore performance is several times higher? Because this is more than Lodash performance is much hi
convenience.4.1. NPMUsing the generator.npmInstall() run npm installation command, Yeoman ensures that the command executes only once, no matter how many times you call it.Generators. Base.extend ({ installinglodash:function () { var done = This.async (); This.npminstall ([' Lodash '], {' Savedev ': true}, done); }}):The above code is equivalent to the command line:NPM Install Lodash--save-dev4.2,
destroyed. For example, it determines whether to destroy it by checking whether the memory usage increases.
2. Use Native JavaScript or Lodash
Lodash simply overwrites some basic logic, rather than relying on the built-in AngularJS method to improve application performance. If your application does not contain Lodash, you may need to rewrite all the code in Nati
React + Webpack construction and packaging optimization, reactwebpack
This article describes how to optimize React + Webpack construction and packaging. The details are as follows:
Use babel-react-optimize to optimize the React code
Check unused libraries and remove import references
Package the class libraries as needed, such as lodash and echart.
Lodash can be optimized using babel-plugin-
2We can see that functional code can easily causeHorizontal scalingThat is, multi-layer Nesting is generated. Here is an example of extreme points.
// Calculate the sum of numbers. // the general method is console. log (1 + 2 + 3-4) // function sum (a, B) {return a + B;} function sub (a, B) {return a-B;} console. log (sub (sum (1, 2), 3), 4 );
This example is for demonstration only.Horizontal scalingAs the number of nested layers of the function increases, the readability of the Code is greatly
APIs.
Classes (Note: Avoid class inheritance.) Read how to use the class and Sleep at night.)
Generators Async/wait: In my opinion, the best way to write asynchronous code looks synchronous. It has a learning curve, but once you learn it, the code is easier to read.
Performance: RAIL?—? starts with Pagespeed Insights webpagetest.org
Progressive Web Application (PWAS): read "Native apps" "why native apps are failing"
N
(1) npm Install bower-g(2) npm Install--global GulpThe first two steps in the CMD run in order to ensure that the global installation, the project will automatically appear in the Bower folder, otherwise there is no such folder, the execution of Bower install will also fail!!If this is done, there is still no bower_components folder in the project . you need terminal in the lower left corner of the project (installed in terminal for the current project installation). npm Install Bower--save-dev
', vendor: [' vue ', ' vue-router ', ' Vuex ', ' Element-ui '] }, // the output here is output in base, not the output of the production output: { path:config.build.assetsRoot, ' [name].js ', ' UMD ', = = = ' Production '? Config.build.assetsPublicPath:config.dev.assetsPublicPath }, externals: { ' Echarts ', ' Lodash ' },This is the comparison before and after the optimi
To use Webpack, first need to run:NPM Install Webpack2. Create a webpack.config.js file:Module.exports = { Entry: './index.js ', Output: { FileName: ' Bundle.js ', Path: __dirname }};3. Using command.js style to exports files, for example:// Alert-button.js var _ = require (' lodash '= { function() { var Alertbuttons = Document.queryselectorall (' [Data-alert] '); function (Button) { Button.addeventlistener (functio
function typeJavaScript is a functional language that takes a function as a class citizen. Functions are also objects in JavaScript (inheritance function), and functions can be passed as arguments to function variables. In recent years, the function has been in high concurrency because of its non-side effects, transparency, lazy computation, etc., and the Big data field has been fired up.JavaScript is also like underscore, lodash and other functional
In daily development, the use of JS third-party libraries or plug-ins is required for agile development or faster meeting business needs.How to introduce JavaScript third-party libraries in Vue projectsGlobal variablesThe simplest way to add a JavaScript third-party library to your project is to window make it a global variable by attaching it to the object.How to introduce:How to use:Export Default { created () { console.log () {_.isempty ()? ' Lodash
;}Model.getcurrentcategoryname = function () {Return currentcategory? Currentcategory.name: ';};});AboveThe GetCategories method is provided externallyIf the categories exists, return promise via $q.when, if categories does not exist, return a $http.get through or then binding promoise.The Getcategorybyname method is provided externally, according to CategoryName to obtain categoryReturns a deferred object via $q.defer, returning promise via Defered.promise. It defines an internal function findc
Let's learn how to unit test your JavaScript with Jest, a JavaScript unit testing the framework from Facebook. We'll install and optimize Jest for this project and see how quick and easy it's to get things going with Jest.Install:NPM I jest-cli--save-devSum.js:var R = require (' Ramda '= sum; function sum (ary) { return r.sum (ary);}Sum.test.js:Const SUM = require ('./sum ') test (' adds 1 + 2 to equal 3 ', () = { expect (sum ([up])). ToBe (3)}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.