Tag Archives: javascript

[Solved] Vue cli installation Fastclick Error

When I installed the fastsclick package into the vue-cli dependency today, it reported an error saying

$ npm install fastclick –save
npm ERR! code ENOTFOUND
npm ERR! errno ENOTFOUND
npm ERR! network request to https://registry.npm.taobao.org/fastclick failed, reason: getaddrinfo ENOTFOUND registry.npm.taobao.org
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network ‘proxy’ config is set properly. See: ‘npm help config’
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Administrator\AppData\Roaming\npm-cache_logs\2021-04-15T12_07_17_780Z-debug.log

Eventually switched to a different installation, typing in the command line.

cnpm install fastclick –save
Success

egg.js The frame post request reported an error of invalid CSRF token security verification, which has been solved

It has to be said that Alibaba’s egg framework is quite good, with its own security verification.

Problem: get request is normal, post request background will report such an error.

" nodejs.ForbiddenError : invalid csrf token"

There is an official explanation for this problem. Click to jump to the official safety explanation of egg. There is not too much explanation here

Method 1: in the confit.default.js Add the following code to turn off security verification (not recommended)

config.security = {
    csrf: {
      enable: false,
    },
  };

Method 2: when the front-end initializes the interface, let the front-end get to request an interface first, and the background returns a secret key to the front-end. Let the front-end put it in the headers request header when the post request is made, and the egg will automatically verify the secret key, and the request will succeed only if the verification is successful.

1. Egg background code, get interface returns secret key: 2

async index() {
    const { ctx } = this;
    ctx.body = {
      csrf:ctx.csrf
    };
}

The following two methods are demonstrated. The postman test is as follows. At the same time, if a request is made in the front end, a secret key pair will be generated in the cookies. As shown in the figure below, the secret key will change after each request, so the CSRF obtained in the front end should be put in the headers request header in a global way.

2. Front end secret key request: 2

axios.post('apis/add', data,{headers:{'x-csrf-token': headData}})

The postman test is as follows: directly copy CSRF

OK, successful request, perfect solution, start moving bricks

How to Use DOM to operate CSS

    1. Modify styles through JS: the styles modified by this method are inline styles with high priority. However, if “! Important” is used in the style, the modification of JS will not work.
	Syntax: element.style.styleName = styleValue ;      
	The style value must be a string
	Note: If the style of css contains " - " , this name is not legal in JS, you need to change this style name to camel naming, remove the " - " and change the
	initial letter to uppercase.

Read style:

	Syntax: element.style.styleName

The styles set and read through the style property are inline styles

    1. get the display style of the current element:
	Syntax: element.currentStyle.styleName 
	currentStyle is only supported by IE browser

In other browsers, you can use the getcomputedstyle() method to get the current style of the element. This method is a window method and can be used directly. This method will return a style object that encapsulates the corresponding style of the current element.

	Two parameters are required
	The first: the element to get the style
	The second: you can pass a pseudo-element, which is usually null

Note: the styles obtained through currentstyle and getcomputestyle are read-only and cannot be modified. If you want to modify them, you must use the style property </OL> to modify them

Solution to electron error “cannot find module app”

Solution:

The original code looks like this:

var app = require('app');
var BrowserWindow = require('browser-window');

To be amended as follows:

const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;

Cause of error: the version of electron used is too new, and this API has been removed in electron v1.0.0. “Cannot find module…” appears again Basically, it’s all because the module is directly introduced by require. If there are errors in the introduction of other modules, you have to check the API now. Not all of them are “const Balabala”= electron.balabala ”For example, the introduction of IPC is:

const ipc = electron.ipcMain;

JQuery is a solution to the disappearance of listening events after adding elements with append

Suppose you want to append an element in the div with ID target
the original listening event format is:

$(".textBox").mouseover(function() {});

To be amended as follows:

$("#target").on("mouseover", ".textBox", function() {});

Add a dynamic box for target ID all the time, not a dynamic box!!! If you really can’t, just let the body go

Solution to inaccessibility of Vue cli scaffold project after startup

The problem is as follows: the IP address cannot be accessed

Enter the file “project name – config”- index.js ”Open index.js File, modify parameter

after modification, it can be accessed normally:

If my article is helpful to you, welcome to like, leave a message and pay attention to it. Thank Sanlian!!!
The problem has not been solved!!! 😘😘😘

CSDN: I heard that you are good at playing
GitHub: zhongzhimao
Coupons: coupons

A JavaScript error occurred in the main process

A JavaScript error occurred in the main process

Running your own software (bonebd) after packaging and installing, an error is reported:

recompiling code also cannot be opened.

Search the% appdata% folder, find the (bonebd) folder and delete it.

Recompile program runs correctly.

Reason:
it may be caused by incomplete software installation, which can be solved by forcibly removing the cache file of the software on the system.

Vue error: error matching template:

The error information is as follows:

the above situation is generally caused by the following conditions:

{% verbatim%} {% endverbatim%} there are unclosed tags or redundant tags (such as div unclosed) in the range of tags bound by the UE instance el. After finding, delete or complete some tag statements cannot be bound by {{MSG}}, but by V-model. For example, input and textarea need to be bound with V-model,

Unexpected token o in JSON at p

Today, using JS to convert a $. Parsejson string to a JSON object will report an unexpected syntax error – unexpected token o in JSON at position 1. I couldn’t find the reason. After the ferry, I saw a sentence: there are strict requirements for JSON to convert objects into strings and store them locally, such as symbols or illegal strings, which may affect the later JOSN.parse The analysis of…

Change {type ‘:’name’} to {type ‘,’name’} and solve the problem

That’s right, JSON is sensitive to single and double quotation marks of strings, which leads to the single quotation mark in the real {} that reported the error…

****Replace single quotation marks with double quotation marks
var_ nstr = _ adrdata.replace (/’/g, ‘”’);

The difference between problem and observables

There is a discussion on stackoverflow: what is the difference between problems and observables?

A useful blog: angular2 observables, HTTP, and separating services and components

An article on the official website of angular: observables compared to other technologies

The difference between observable and promise:

Observables are declarative; computation does not start until subscription. Promises execute immediately on creation. This makes observables useful for defining recipes that can be run whenever you need the result.

Observable is declarative, and calculation is not triggered until subscription. This is very different from promise — promise is executed immediately after it is created.

Observables provide many values. Promises provide one. This makes observables useful for getting multiple values over time.

Observable provides multiple values, while promises can only provide a single value.

Observables differentiate between chaining and subscription. Promises only have .then() clauses. This makes observables useful for creating complex transformation recipes to be used by other part of the system, without causing the work to be executed.

Observable can be combined into complex transformation recipes with the help of rich operators in rxjs, which is convenient for reuse in application, while promise has only one then operation.

Observables subscribe() is responsible for handling errors. Promises push errors to the child promises. This makes observables useful for centralized and predictable error handling.

Uncaught Error: THREE.OBJLoader : unexpected line: “DOCTYPE HTML” [solved]

Today’s problem really makes me despair. What you netizens say is that it’s OK to put it under static, but I can’t do it here 😥
Then I found that I had a static folder under public. After testing, I found that it was really static under public….
The code can still be written as usual

summary
obj file is put under public/static
questions
but why I don’t understand?If you know, please leave a message in the comment area 😁

Arrow function should not return assignment no-return-assign

Arrow function should not return assignment no return assignment.

This paper describes the problems encountered in learning p221 of the latest Vue and vuejs in 2019, from introduction to mastery. Because the checking code of eslint is referenced, the checking error is reported. There is no problem with the code, it is the problem of eslint checking.
Solutions: 1. Remove eslint
2. Modify the code to conform to eslint
original code

   if (this.isSelectAll) {
        this.cartList.forEach(item => item.checked = false)
      } else {
        this.cartList.forEach(item => item.checked = true)
      }

Changed code

   if (this.isSelectAll) {
        this.cartList.forEach(item => { item.checked = false })
      } else {
        this.cartList.forEach(item => { item.checked = true })
      }

After learning the arrow function, we can know that the {} added can be omitted, but the rule of eslint requires this.