Skip to main content

Posts

Showing posts from September, 2022

remote: Support for password authentication was removed on August 13, 2021. remote: Please see https://docs.github.com/en/get-started/getting-starte...

 I haven't used git for a long time. When I opened it, I found that there was an error in push. I was very confused? What is the situation? It probably means that your original password credentials will not be available from August 13, 2021. You must use a personal access token (personal access token), that is, replace your password with a token!

vue routing global guard beforeEach and afterEach

 Global routing front guard (beforeEach) This function is used the most. Its function is to perform permission-related verification before routing jumps. This function contains three parameters: to: the object of the target route that is about to enter; from: the route that the current route is leaving; next: confirm the release. It can be used to log in and register, to determine whether there is a token before logging in, and release if it exists. , if it does not exist, it will not be released. The post routing guard (afterEach), its role is to trigger after the routing jump.

Two lifecycle hook functions activated and deactivated in Vue routing

 The creation and mounting of components that use the cache <keep-alive> at the beginning will be executed the same as the components that do not use the cache, but the components that use the cache will not be destroyed when switching components, and the activated function will be triggered when switching back again. , the deactivated function will be triggered when switching, and components that do not use the cache cannot use the activated function. Simply put, the activated function is a hook function after the page is activated, which is triggered as soon as the page is entered. So when we use component caching, if we want to send a request every time we switch, we need to write the request function in activated, and in created or mounted, it will only work when the component is loaded for the first time.

The use of vue cache routing components

 When we switch from one component to another, the routing component that has not been displayed remains mounted and not destroyed. When we switch back, the previous data is still maintained, for example, entering data in a text box, Then switch to another page, and then switch to the previous text box interface, the data of the text box is still saved. The web page experience will be better.

Usage of Vue Router

 The main feature of SPA single page is that a layer of front-end routing is added on the basis of the separation of front-end and back-end. That is, the front end maintains a set of routing rules. The user clicks the routing link on the page, which causes the Hash value in the URL address bar to change. The front-end routing monitors the change of the Hash address, and the front-end routing renders the component corresponding to the current Hash address to the browser. Vue-router is the routing solution officially given by Vue. It can only be used in conjunction with the vue project, and can easily manage the switching of components in the SPA project. For VueRouter, routing is the decision-making process of selecting a component for rendering based on a request path.

mapState, mapGetters, mapMutations, mapActions in vuex

 The above four objects are all in the vuex plug-in store, which is often used to store some data shared globally. But I still feel a little uncomfortable when using it, that is, I wrote a lot of repeated prefixes. At this time, these four objects appeared, which solved this pain point very well. mapState is mainly used to manipulate and obtain data, mapGetters is equivalent to computed properties, and mapMutations and mapActions are simplifications of mutation and action. They can be written as both objects and arrays.

Destructuring assignment in ES6

 In the past, when we wanted to assign a value to a variable, such as an array type and an object type, to assign a value to a variable, we could only specify the value directly. It is very troublesome to write in this way, but under the ES6 syntax specification, it is allowed to directly extract the required values from arrays and objects according to a certain pattern, and directly assign variables to variables. This method is called Destructuring, which is simple to understand. That is, the left and right sides of the equal sign are equal.

Access to XMLHttpRequest at 'http://localhost:8080/xxx' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

 Due to browser same-origin policy restrictions. The Same Origin Policy is a convention. This is the main and essential security feature of the browser. Without the same-origin policy, normal browser functionality may be affected. The web is built on the same-origin policy, and browsers are just one implementation of the same-origin policy. The Same Origin Policy prevents JavaScript scripts from one domain from interacting with content from another domain. The so-called same origin (that is, the same domain) means that two pages have the same protocol, host and port.

favicon.ico 404 Not Found Causes and Solutions

 What is favicon? It is the abbreviation of Favorites Icon. Its function is that in addition to displaying the corresponding title in the browser's favorites, icons can also be used to distinguish different websites. When I encounter this kind of error, I feel very uncomfortable. There is obviously no problem. Why is a 404 error reported? The following is the solution.

Using ref to bind elements in Vue

 Vue provides us with a property to manipulate dom, ref. When bound to the dom element, it is used similar to the id. It is called through this.$refs, and it can also be bound to the component. It is very troublesome to obtain DOM elements in the previous native way. It needs to be obtained with such a long AP as: documentgetElementXXX/querySXXX.... Then jQuery was born to solve this pain point. The use of $("id") makes Our operation has become easier. But there are other problems, jQuery is just a library (plug-in) and cannot be used to build a framework. Now Vue can help us solve this problem. Vue also has its own method to obtain DOM, which is ref. It can get not only DOM elements but also components. If you add ref to the dom element, you can get the dom element, and if you add it to the component, you can get the component instance, and you can use the component method.

What is Vue Global Event Bus?

 The global event bus is not a native API provided by Vue. It is a clever design method summarized by developers in practice. Its principle is to add a property to the prototype of Vue. Once this property is added, Vue Instances and vue components can use this property with the help of prototypes, so as to realize the intercommunication and transfer of data between data. If we need to implement complex communication between components, it is not so convenient to use the props properties of parent and child components. We have written a lot of redundant code layer by layer. At this time, we can use the message bus writing method, which is more simple and convenient. 

Use of custom events in Vue components.

 The parent component uses props to pass data (such as a method) to the child component, and the child component needs to use custom events to pass data back to the parent component! We can use v-on to bind custom events, and then pass them to subcomponents, which will call after receiving the method. Each Vue instance implements the Events interface, that is: use $on(eventName) to listen for events and $emit(eventName) to trigger events.

Use of browser objects localStorage and sessionStorage

 The main difference between them is: one exists locally, the other is a temporary session, and the storage time is different. The data saved in localStorage exists for a long time. When we visit the website next time, the webpage can directly read the data saved before; the data saved in sessionStorage is used for a session of the browser. When the session ends, such as closing the browser After the window, the data will be cleared. Aside from the difference in shelf life, the two objects are otherwise identical. The data they store is in the form of "key-value pairs". That is, each item of data has a key name and corresponding value. All data is stored in the form of strings. Due to cross-domain restrictions, they are only used on the client side and do not communicate with the server side.The size of the stored data is generally 5M.