vue-cli initializes a method instance of a vue.js project
Parsing packaged .vue files
In order to enable us to better maintain components during project development, vue provides a single-file component system. vue puts each independent component in a. In the vue file, three basic custom tags are provided in this file:
1. template
2. script
3. style
to place different content blocks of components, but because of the browser This file type cannot be directly identified, so we need to compile and package it through webpack. The official provides a loader for processing .vue: vue-loader
ERROR in ./src/Hello.vue
Module build failed: Error: Cannot find module 'vue-template-compiler'
Vue is actually developed using a .vue single-component system, but it cannot adapt to actual complex needs. We still need to configure a lot Some things are integrated with .vue. This configuration is very cumbersome, so the official provides a tool to help us build some content that must be used in the development process of a project. This tool: vue-cli, through this tool we can It is very convenient to create a project based on vue. We also call this tool --- scaffolding
installation
npm install vue-cli -g (global)
or
yarn global add vue-cli
After we install the vue scaffolding through the above method, we can use a command in the command line: vue (this command does not have -cli)
Usage of vue
vue init
init: Initialize (create) a project based on vue
vue init webpack hello: Build a project named hello based on webpack vue project (project construction must be online! Network! Network!)
vue-cli is an interactive command line. Building the project through the vue command will require us to fill in some project information:
Project Name: The name of the project to be created (this command will produce a package.json file. The name option in the file is the ProjectName. The default is the name of the currently created project directory. You can also make it yourself (but it needs to comply with the name naming rules in package.json. Do not use capital letters, spaces, or underscores. You can use -)
Project Description: Project introduction, will also appear in the package.json file, optional
Author: author, optional
Press Enter directly in the next step
Install vue-router: Whether to install the vue routing component. If you are doing a project, you must install it.
Use ESLint to lint your code: Do you need to use ESLint? Module for code detection
Setup unit tests with Karma + Mocha?:Whether to install tests (unit tests)
Setup e2e tests with Nightwatch?:Whether to install end-to-end tests
Complete the above steps, over!
After completing the configuration through vue-cli, the next step is to install the dependency packages required by vue. The dependency packages that the project needs to install are described in the package.json file automatically generated by the vue-cli tool:
dependencies: dependency packages that actually need to be used in the project
devDependencies: some toolkits that need to be used during the project development process, which are not part of the actual online code of the project
Run
After the required installation dependency packages are installed, you can start the project and run
yarn run dev / npm run dev: open a test development environment
yarn run build: build the project and package the project , we can upload the packaged project files to the server
If it is the first run, you will see a welcome page, and then we can proceed with project development
Project structure
build directory: Some script files and configuration files needed to build project commands
config directory: A small file will be automatically installed in vue-cli The hot reload web server built by express, the config contains the relevant configuration of this server
dist directory: the storage directory after the project is compiled and built online
node_modules directory: project dependency package storage directory
src directory: project source code storage directory
static directory: static resource storage Directory
During the project development process, most of our tasks are completed in the src directory
main.js: vue scaffolding is the entry file set in the project that we automatically generate. In this entry file, some project initialization work is done
Introduce Vue
Introduce necessary components
Create Vue instance
Routing
When our application becomes complex, the number of pages involved will also increase, and the logic will also become complex. It turns out that we organize and maintain our website through multiple pages. , but this kind of user experience is not very good (because the page will be refreshed or jumped). In order to solve the user experience problem, the best way is to use data (the page will change), but there is no need to jump or refresh.
Get data asynchronously through ajax without refresh
After obtaining the data, it is processed and managed through vue and the page is rendered
Under what circumstances do you get the data to render the page? Traditional processing method: resend the request through the URL to obtain new data and pages. What page data to obtain is determined by the URL. If you use the single-page development mode, you can no longer use page jumps, but you can use the hash value in the URL. changes to determine what content to obtain and what page to render.
So the hash of a url corresponds to a view, then we need to set the relationship between hash and view. We can make a corresponding relationship (mapping) between hash and view.
- Set the map of hash-view ( Mapping) relationship
- Monitor hash changes
- When the hash value changes, find the corresponding component according to the map to render the view
vue provides us with a third-party framework to implement the above Function: vue-router
The address-view mapping we mentioned above: routing
Related recommendations:
vue-cli is simple to develop multi-page applications Example
vue-cli writing vue plug-in instance
The above is the detailed content of vue-cli initializes a method instance of a vue.js project. For more information, please follow other related articles on the PHP Chinese website!

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software