Tag Archives: javascript

JavaScript solves let statement error in code

directory
Question 2. Answer


Problem 1.
Why do we need var instead of let in JavaScript code?

2. Answer
JS version compatibility issues, ECMAScript 6 can be changed.
ES 5; After ES 6, let is used for variable declarations, and const is used for constant declarations. They are used to replace the var declaration method in ES 5.


The original link: https://qwert.blog.csdn.net/article/details/106248417

HTTP error 401 and 403 detailed explanation and solution

A, 401:
1. HTTP 401 Error – Unauthorized: (Unauthorized)
Your Web server believes that the HTTP data stream sent by the client is correct, but access to the URL resource requires user authentication, and the relevant information 1) has not been provided, or 2) has been provided but has not passed the authorization test. This is commonly known as “HTTP Basic Validation.” The authentication request that is required from the client is defined in the HTTP protocol as WWW — Authenticate Header Field

Desktop applications usually do not use cookies. Instead, they send the “user name + colon + password” as a base64-encoded string in the header Authorization of the HTTP request to the server. This method is called HTTP Basic Authentication.

2. The reason:
Since the request does not contain the Authorization header, the server will return a 401 Unauthozied to the client and add the information in the Response header “WWW -authentivate”. When the client encodes the user name and password with Base64 encryption and sends it to the server in the Authorization header, the authentication will be successful.

3. Scenarios and methods:
This is the interface of the user token. All the Body request parameters and Headers are the same, but the 401 error is reported. Haha, I forgot to add the request Header for Authorization. The solution is to add a keyvalue pair for basic authentication in HEADERS. The key-value pair is as follows:
Authorization:Basic YKKOw9MPlY3JldA== (Note: Base64-bit encoding here is written arbitrarily, please feel free to read) Authorization:Basic YKKOw9MPlY3JldA==
http://blog.csdn.net/u013136708/article/details/41210897

Second, 403:
1. HTTP 403forbidden – Access denied
403forbidden is a Status Code in the HTTP protocol. You do not have permission to access this site.

This state represents
The server understood the request but refused to execute the task. The request should not be re-sent to the server. In cases where the HTTP request method is not “HEAD” and the server wants the client to know why the permission is not available, the server should describe the reason for the refusal in the message returned. In cases where the server does Not want to provide any feedback, the server can use 404 Not Found instead of 403 Forbidden.

2. The reason:

You don’t have permission to access/on this server.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

3. Scenarios and methods:

I happened to see this error 403 a few days ago. Our link address was https://www.ceshi.com at that time. But it was configured as http://www.ceshi.com by someone else; This will result in a 403 error. The solution: just change HTTP to HTTPS.

On closer inspection: the error should be 403.4. 403.4 error is caused by requiring SSL, you must use “HTTPS” in the address of the page you want to view.

When react dynamically prunes components by operating arrays, the state of the remaining components is not preserved. Solution to the problem (method of dynamically setting unique key value)

Problem: There is A public component A whose parent component B renders A by iterating through the array. Dynamic addition or deletion of an array is the same as dynamic addition or deletion of component A. The problem is that the user is responsible for adding and deleting, so there is no way to give a fixed key at the beginning. In the beginning, index is used as the key value, but adding or deleting components will refresh the key value of previous components, resulting in the state cannot be preserved.
solution:
br> a>

>

V-for styles individual elements

v-forts styles for individual elements
v-formponent can loop through a bunch of components. However, when styling, there is a need for individual elements to be styled in such a way that they are highlighted.

<card-grid
        style="width:25%; text-align: center"
        v-for="(item,i) in menuItems"
        :key="i"
        ref="items"
        :style="i === itemIndex ?chosenStyle:'' "
      >
        {{ item.name }}
      </card-grid>

itemIndex as needs to be individually styled sequence, when the I render time and itemIndex is equal, this component will be separately set a : style = 'chosenStyle' , can achieve the corresponding effect.

Ueditor paste word image and upload image file automatically

Tinymce is a very good rich text editor, you can go to the website to download. https://www.tiny.cloud
Here is the source code of PowerPaste, a paid plug-in on its official website, but it does not affect the use of functionality.

umeditor+粘贴word图片


Take Vue as an example:
Install Tinymce under static directory instead of NPM.
PowerPaste is put in the \static\tinymce\plugins directory


Introducing tinymce.min.js in index.html.


Code parameter configuration is shown in the figure below:


Replace paste in plugins with powerpaste and you’re done.
The final effect, can automatically batch upload all the images in Word

After the picture is uploaded, the image address in the editor is changed to the image address of the server.

Practice — CSS3 — frame animation to achieve special effects

Practice ING – Frame animation to achieve special effects
Recently, I wrote another requirement, which used a lot of CSS3 animation, but it is still very deep to go into each attribute of CSS3 animation carefully. Here, I will write down the understanding of the steps attribute of frame animation
We know that CSS3 Animation has eight attributes
animation-name
animation-duration
animation-delay
animation-iteration-count
animation-direction
animation-play-state
animation-fill-mode
animation-timing-function
Most 1-7 are introduced, but the animation-timing function is an attribute that controls the time
In addition to the three Bessel curves commonly used, there is the confusing steps() function
By default, the animation ease the transition. It inserts a tween between each key frame, so the animation is coherent
In addition to ease, transition functions such as Linear, Cubic – Bezier will insert the tween for it. However, some effects do not require tween, but only a jump between key frames, where steps should be used
Understand the steps
The Steps function specifies a step function
The first parameter specifies the number of intervals in the time function (must be positive integers)
The second parameter, which is optional, accepts both start and end values, specifying a step change at the start or end point of each interval, which defaults to end.
Step -start is equal to steps(1,start). The animation is divided into 1 step. The part that starts the left endpoint when the animation is executed is the beginning.
Step-end is the same as steps(1,end) : the animation is divided into steps, and the animation is executed starting with the end endpoint, with the default value of end.
Look at the W3C specification
The wrong understanding of the first parameter of steps:
Steps (5, start)
The first parameter “number” of steps() is the specified number of intervals, that is, the animation is divided into N-step phased display, which is estimated to be the number of changes written for keyframes by most people
A look at the cSS2 frame animation I wrote also gave me a good understanding of cSS3 animation
@-webkit-keyframes circle {
0% {}
25%{}
50%{}
75%{}
100%{}
}

I also wrote a js, please refer to

Browser performance tool

Why use Performance
The purpose of GC is to realize the virtuous cycle of memory space
; the cornerstone of the virtuous cycle is to use
properly at all times to determine whether it is reasonable
Performance provides multiple monitoring methods
Open a browser and enter the target website
into the developer tools panel. Select the Performance
to open the recording function. Visit the specific interface
to perform user behaviors

interface appears lazy loading or frequent pauses
interface continues to show poor performance
interface performance becomes worse and worse with time delay
The way to monitor memory
standard
memory leak: is the continuous increase of memory
memory bloat: performance problems exist on most devices
frequent garbage collection: analyzed by memory change graph
Method:
browser task manager
Timeline graph record
heap snapshot lookup decouple DOM
determines whether frequent garbage collection occurs

How to use JavaScript in HTML

Statement: All of my blogs are personal notes, used as personal knowledge index, so there are logic problems in the narrative, the span is large, I hope to understand. Share out for everyone to learn to read, if there is a mistake hope to point out, thank you!

< script> Tag properties:
Async: Optional, indicating that the script should be downloaded immediately but should not interfere with other operations on the page
Defer: Optional, which means that the script can be deferred until the document is fully parsed and displayed, and is valid only for external scripts
SRC: Optional, representing the external file that contains the code to execute
Type: Required, representing the content type of the scripting language in which the code is written, typically text/javascript
Use external JavaScript files
In the use of & lt; script> When embedding external JavaScript code, do not appear anywhere in the code. /script>
If you want to pass < script> Element to contain an external JavaScript file, then SRC is required. SRC points to a link to an external JavaScript file, either relative or absolute
The processing of the page also stops temporarily when downloading and parsing external JavaScript files
& LT with SRC attribute; script> JavaScript code should no longer be included between tags, and even if it was, it would be ignored
External JavaScript files carry a.js extension that can be ignored, but the server must return the correct MIME type
Label location
Placed in & lt; body> At the end of the
Because: The browser processes the HTML code sequentially, if placed at the beginning will cause the browser to first download and process the JavaScript external files, thus causing the web page to be placed in the < head> And add defer= “defer”

<script type="text/javascript" defer="defer" src="xxx.js"></script>

The because: Defer property causes the script to be deferred until the entire page has been loaded, called the defer script, which is best left with only one placed at < head> In, and add Async

<script type="text/javascript" async src="xxx.js"></script>

The because: Async attribute instructs the browser to download the script file immediately, but it should not prevent other actions on the page marked async from ensuring that the script is executed in the order in which it is recommended to place the script at < body> The end of the method

Uncaught Error: Script error for ” popper.js “, needed by: bootstrap solution

Uncaught Error: Script error for "popper.js", needed by: bootstrap
https://requirejs.org/docs/errors.html#scripterror
    at makeError (require.js:168)
    at HTMLScriptElement.onScriptError (require.js:1738)

This error is caused by Bootstrap’s dependence on the popper.js component. Bootstrap relies on jQuery or some plug-ins that depend on popper.js.
I found a solution online.

require(["popper"], function(popper) {
    // set popper as required by Bootstrap
    window.Popper = popper;
    require(["bootstrap"], function(bootstrap) {
        // do nothing - just let Bootstrap initialise itself
    });
});

Try it, the problem is still unsolved.
Then start with bootstrap.
The previous code in bootstrap looks like this.

(function (global, factory) {
  typeof exports === 'object' && typeof module !== 'undefined' ?factory(exports, require('popper.js'), require('jquery')) :
  typeof define === 'function' && define.amd ?define(['exports', 'popper.js', 'jquery'], factory) :
  (factory((global.bootstrap = {}),global.Popper,global.jQuery));
}(this, (function (exports,Popper,$) { 'use strict';

Manually change the configuration in RequireJS to require Paths instead of popper.js. My configuration looks like this.

'popper':                 'popper.js/dist/umd/popper.min',

Therefore, directly change the first few lines of bootstrap source code popper.js to popper to solve the problem.
 
However, I think it is inappropriate to change the source code in this way. So he looked for a solution.
 
The ultimate solution is this.

require.config({
  baseUrl: '/vendors',
  paths: {
    'jquery':                 'jquery/dist/jquery.min',
    'bootstrap':              'bootstrap/dist/js/bootstrap',
    'popper':                 'popper.js/dist/umd/popper.min',
    ...
  },
  shim: {
    'bootstrap': ['jquery']
  },
  map: {
    '*': {
      'popper.js': 'popper'
    }
  }
});

The core solution is:

Add a map configuration in the configuration of require

‘popper.js’: ‘popper’
 
And then I met,
Datatables.net – BS4 relies on datatables.net as well.
Add a row to the map to configure:
‘datatables.net’: ‘datatables’

Reproduced in: https://my.oschina.net/justplay/blog/2992283