VUE Learning - Scaffolding Project

VUE component base

insert image description here
insert image description here
insert image description here
The root component APP is what we wrote in () before, but it is extracted into a separate APP object
insert image description here

component tree

insert image description here
Components are objects

How to register components

insert image description here

Register global components

app.component("component name", component) The middle part of the component name -
insert image description here
the structure of the .vue file will be clearer later, it is not written like this

At present, the way of writing can be improved, put the template in html to write and bind it with id
insert image description here

The logic of the global component

insert image description here
Because it is an object, all can have these methods!

component name

They are all named with -, the most commonly used, and the hump case is rarely used. The home-nav
insert image description here
html element is not case-sensitive when it is recognized, so it does not support the recognition of hump-named components, but it can be recognized if it is recognized in the template of the vue file.

Features of Global Components

Once registered, it can be used anywhere, and global components can be used in other components, and it will also be displayed, which is equivalent to calling between components

Local components (components are really commonly used)

insert image description hereRegister in the app (root component), and write it in a way like methods and computed. At this time, these components can only be used in the root component, but these components cannot be called in other components.
insert image description here
If you want to use a local component in a component, you need to register this component in your own component to call
insert image description here

However, all the components that are actually developed will be written into the .vue file, so the above is just an example to introduce, in practice, it will not be written like this, because such code logic is very messy

Question: What
insert image description here
we hope is that the logic and the template are together in a component, so that we can find it at once

Vue development mode (how to write in real development)

insert image description here
I hope that the components can be achieved (here I think it is still necessary to separate from the idea of ​​jsp, it just writes components like this, which is convenient for modification, but not everything on the page is also kneaded together), but the vue file browser does not recognize it
insert image description here
, So you need a packaging tool to package it and then the browser can recognize it (I think this is like packaging it into a war package and then deploying it???)

insert image description here

Single File (SFC)

insert image description here

VUE CLI Scaffolding

I feel that this is not the feeling of creating a module in the idea, that is, moving the back-end things forward, or this is the general development idea. (The early stage is all foreshadowing, and finally leads to this scaffolding, which is very good, showing the role of scaffolding, why modular development is needed)
insert image description here

Introduction to CLI (CLI: Command Line Interface)

insert image description here
npm install global CLI
insert image description here

Preparations (download node.js and git)

git has been downloaded before.

I download node.js installation myself

nodejs understanding

What is nodejs ?
Now I think the best explanation is that nodejs is a JS language interpreter, so that JS can also be used on the back-end server. In the past, JS could only be executed in the operating environment such as the browser. With nodejs, you can It can also be executed in the background, so that js can get through the front and back ends.
Node.js is a Javascript runtime environment based on the Chrome V8 engine.
So Node.js is not a library, but a runtime environment, or a JS language interpreter.
(It is an environment for executing js. It contains the V8 engine of chrome, which is designed to be used as a web server.)

npm understanding

There are many JS developers, so there are many people who contribute open source code, all of which condense into npm, the largest software package warehouse in the world.
npm is the abbreviation of Node Package Manager, which means Node's package management system. Nodejs is now in full swing, and npm https://www.npmjs.com/ has contributed a lot. Here, if we want to implement various functions, we can almost find ready-made packages written by others, just use them directly.

installation process

Here I just look at the download process on the Internet, there are many, mainly to configure a global folder and cache folder, configure two variables, and change the address of the mirror, there are many online processes.
nodejs installation tutorial
Install the latest version of npm (the npm command is used on git in the video) and
insert image description here
you can use the npm command when you go to git to see it.
insert image description here
Then I downloaded the scaffolding in git, command: npm install @vue/cli -g (the following -g indicates that it can be used globally)
insert image description here

A problem before using nodejs command in vscode

When learning to use scaffolding, it is still a bit troublesome to configure nodejs and vue scaffolding. It is uncomfortable to think of these configurations. The first problem encountered is how to solve the use of scaffolding on vscode. First, download nodejs, and then in
git Configure the global npm to install the global CLI.
I thought it could be used, but then found that it could not
solve the VSCODE "because running scripts is prohibited on this system" error.
After learning from this blog, it really succeeded, and I am very happy
insert image description here

Use scaffolding steps

insert image description here

insert image description here
One more step in coderwhy is to ask him whether he needs to configure the mirror, and the variable configured in my node at the beginning is the mirror of Taobao, so there is no such question.
insert image description here
1. First check whether the installation is successful in vscode
2. Use the Vue create project name to create the project, pay attention to the underscore
3. Choose to use vue3, vue2 or manually select the new feature (preset: prediction), here choose manual configuration
insert image description here
4. Currently only Babel is used (Babel is a JavaScript compiler, which is mainly used to convert code written in ECMAScript 2015+ syntax into backward compatible JavaScript syntax,) other routes are currently not used, and can be selected later.
Click the space to select, a select all
insert image description here
5. Select vue3 learned in version 3.x
insert image description here
6. Choose where to put babel and other things, the independent configuration file is still package.json (choose independent, because it is convenient for configuration)
insert image description here
7. Do you want to put The thing you generated before is made into a prediction, which can be used directly later, without having to do it manually.
insert image description here
I choose yes, so enter a preset name and I set it to vuedemo.
insert image description here
The project is created successfully
insert image description here
. It looks like this
insert image description here

CLI project structure analysis (must be mastered)

insert image description here
jsconfig.json is for vscode. components are used to store components

package.json

package.json contains the modules needed to run the project, and it is a packaging configuration file. You must understand that
entering package.json to view
vue-cli-service is a package for webpack.
serve is to enable local services, and bulid is
insert image description here
to enter before entering the package project CD the project directory (you can also click on the file directory to open it in the integrated terminal)
(here is really the same as the linux command, it should be because nodejs is used as a server environment, so this command is used.) Enter
npm run serve will automatically help us package the current project and start the local service (here you can also see that nodejs is used as a server). The
insert image description here
first package will be slow, so wait patiently for
success. See the familiar 8080 port, It's really a server release, my family!
insert image description here

.browserslistrc for browser adaptation

It’s enough to understand it. Generally, the default
insert image description here
main.js is the main file.

real component usage

Only after importing and then registering can it be used.
Keep in mind:
the object passed into createApp is actually a component, and each application needs a "root component", and other components will be its subcomponents.

insert image description here

export and import in vue

The export default export command in Vue
has a name for the external interface, and the variable name imported by the import command from the module is the same as the name of the external interface of the imported module.
However, the variable name output by the export default command can be arbitrary. At this time, braces are not used after the import command.

The export default command is used to specify the default output of the module. Obviously, a module can only have one default output, so the export default command can only be used once.
Therefore, there is no need to use braces after the import command, because it can only correspond to the export default command.

jsconfig.json description (why it is used for vscode)

Here you need the knowledge of webpack
to understand this, but it is especially useful later. In order to better prompt the code
insert image description here
to configure the alias of the path, there is a problem here, that is, there is no prompt when writing the path alias utils, and vscode does not know that you are in webpack The alias configured in , so you need to configure it in jsconfig.json to let vscode know, which is why it is used to configure vscode.
insert image description here
Configure the path of utils in it, so it can be automatically recognized
insert image description here

Processing of templates in different versions of VUE (understanding)

I'm a bit confused about
the entire rendering process of vue.
insert image description here
All templates must be rendered . Webpack will process the vue file and convert it directly
insert image description here
to you. more succinct
insert image description here

insert image description here

insert image description here

insert image description here

After reading it, it is the difference between whether the compilation of the template is done by the vue source code, or by the vue-loador in the vue scaffolding for you. The vue called is different, which is the underlying thing of vue
insert image description here

vscode plugin

Volar has better support for vue3
insert image description here

new development model

insert image description here
To convert the development idea, the next step is to write each component, and the component tree composed of each component and the root component.
Because it is packaged by webpack, main.js is the entry point (here we need to learn webpack)

Scope issues with single-file style

It is indeed a problem, it is a global scope, so you need to add something
insert image description here
to add the scoped internal principle to the style of each single file
insert image description here
: add an identification number to the modified element of each single file, that is Now I know who it was that was modified.
insert image description here

vue error "'vue-cli-service' is not an internal or external command, nor..." solution (mainly encountered when importing other people's projects)

I met the previous answer from the brother of Boxing, which is very well written.
It is to npm install first. This command is an installation dependency (node_modules is a dependency, and it cannot run without it, so you can also pay attention to it before running it in the future)
vue reports an error" 'vue-cli-service' is not recognized as an internal or external command, nor..."

Vite creates a vue project

After entering npm init vue@latest, start to create the project.
The packaging efficiency is very high.
insert image description here
After entering the command, follow the prompts step by step from the project name to the various plug-ins required by the project. It is very concise and clear, which is easier to use than scaffolding
insert image description here
. Follow the prompts he gave to input step by step, first switch to the project directory, then install the dependencies (npm install), and run dev not serve, it will run successfully. The interface after
insert image description here
success
insert image description here

There are some differences between the configuration and scaffolding on vite, and it feels more reasonable overall.
insert image description here
And in the end, when the project was deleted, I found that there were a lot of things in the scaffolding project, and there were a lot less vites

Guess you like

Origin blog.csdn.net/Tommy__li/article/details/128043345