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!

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).

JavaScript is a programming language widely used in web development, while WebSocket is a network protocol used for real-time communication. Combining the powerful functions of the two, we can create an efficient real-time image processing system. This article will introduce how to implement this system using JavaScript and WebSocket, and provide specific code examples. First, we need to clarify the requirements and goals of the real-time image processing system. Suppose we have a camera device that can collect real-time image data
