Home Web Front-end JS Tutorial Vue project construction and practical example tutorial

Vue project construction and practical example tutorial

Jun 28, 2017 pm 01:05 PM
Actual combat Construct project

Due to Vue’s relatively gentle learning process and novel technical ideas, it has been favored by the majority of front-end and back-end developers. At the same time, its easy-to-understand API and data binding functions have also won its popularity. Many users. This article mainly explains the construction and actual implementation of the Vue project, so it will not cover too much its API and syntax. It is designed to help entry-level users of Vue understand the steps and methods of building a Vue project from scratch.

First of all, before building a vue project, we need to understand the classification of vue projects. Here I mainly divide them into two categories: (1) Directly introduce the vue.js file (2) Use vue single file components

According to the above two categories, directly introducing the vue.js file is like directly introducing jQuery into the page. Such a project has many flaws and can only use some basic APIs and limited functions. It is generally mainly used for Beginner users and small projects. This article mainly explains the second type of Vue project built using Vue but with file components.

There are many ways to build a vue project. First, we need to use the corresponding construction tools. The officially recommended build tools mainly include webpack and browserify. Here I recommend that you use webpack for building. At the same time, in addition to building tools, we also need to use building methods. For example, we can use vue-cli scaffolding to automatically generate the base directory file of the vue project. Of course, we can also customize the build from scratch.

vue-cli build

If you use vue-cli scaffolding to build a vue project, then you only need to type the following 5 lines of commands to generate a simple vue project (prerequisite is to install node .js):

npm install -g vue-cli
vue init webpack my-project
cd my-project
npm install
npm run dev

This construction method is not suitable for all projects. Many files may not be used in your project, and if you know nothing about the automatically generated files, it will be very difficult to maintain them later. Therefore, it is not recommended for novices to use vue-cli to build. Instead, it is recommended that everyone build a vue project from scratch by referring to the files generated by vue-cli.

Custom build

Compared with vue-cli build, custom build is much more flexible, but it requires you to understand the steps and principles of construction, and the requirements are accordingly increased. The custom build is divided into the following steps:

File/folder creation

package.json file creation

webpack configuration file creation

Entry file creation

Vue component writing

Routing configuration

package.json file

Using the following command, we can quickly create a package.json file:

npm init -y

Then modify its scripts configuration items, add packaging and compression commands, and add dependencies and add corresponding project dependencies.

webpack configuration file

Secondly we need to create our webpack configuration file. The difference here from building other projects is that the vue single file component needs to be loaded using the vue-loader loader. At the same time, use babel-loader converts ES6 syntax

Entry file

Here we need to write the entry.js of the entry file address configured in webpack. The main function is to mount the generated vue instance app to the DOM node with the ID of app

Then we need to write the final Simple vue component index.vue, place it in the views folder

This article mainly introduces two ways to build vue projects, vue-cli build and custom build have their applicable scope and objects , everyone needs to make the best choice based on the project and their own conditions. At the same time, there are many functional configurations in the custom build that are not mentioned in this article. Interested children's shoes can continue to explore on their own.


The above is the detailed content of Vue project construction and practical example tutorial. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Can AI conquer Fermat's last theorem? Mathematician gave up 5 years of his career to turn 100 pages of proof into code Can AI conquer Fermat's last theorem? Mathematician gave up 5 years of his career to turn 100 pages of proof into code Apr 09, 2024 pm 03:20 PM

Fermat's last theorem, about to be conquered by AI? And the most meaningful part of the whole thing is that Fermat’s Last Theorem, which AI is about to solve, is precisely to prove that AI is useless. Once upon a time, mathematics belonged to the realm of pure human intelligence; now, this territory is being deciphered and trampled by advanced algorithms. Image Fermat's Last Theorem is a "notorious" puzzle that has puzzled mathematicians for centuries. It was proven in 1993, and now mathematicians have a big plan: to recreate the proof using computers. They hope that any logical errors in this version of the proof can be checked by a computer. Project address: https://github.com/riccardobrasca/flt

Share an easy way to package PyCharm projects Share an easy way to package PyCharm projects Dec 30, 2023 am 09:34 AM

Share the simple and easy-to-understand PyCharm project packaging method. With the popularity of Python, more and more developers use PyCharm as the main tool for Python development. PyCharm is a powerful integrated development environment that provides many convenient functions to help us improve development efficiency. One of the important functions is project packaging. This article will introduce how to package projects in PyCharm in a simple and easy-to-understand way, and provide specific code examples. Why package projects? Developed in Python

A closer look at PyCharm: a quick way to delete projects A closer look at PyCharm: a quick way to delete projects Feb 26, 2024 pm 04:21 PM

Title: Learn more about PyCharm: An efficient way to delete projects. In recent years, Python, as a powerful and flexible programming language, has been favored by more and more developers. In the development of Python projects, it is crucial to choose an efficient integrated development environment. As a powerful integrated development environment, PyCharm provides Python developers with many convenient functions and tools, including deleting project directories quickly and efficiently. The following will focus on how to use delete in PyCharm

PyCharm Practical Tips: Convert Project to Executable EXE File PyCharm Practical Tips: Convert Project to Executable EXE File Feb 23, 2024 am 09:33 AM

PyCharm is a powerful Python integrated development environment that provides a wealth of development tools and environment configurations, allowing developers to write and debug code more efficiently. In the process of using PyCharm for Python project development, sometimes we need to package the project into an executable EXE file to run on a computer that does not have a Python environment installed. This article will introduce how to use PyCharm to convert a project into an executable EXE file, and give specific code examples. head

PHP Practical: Code Example to Quickly Implement Fibonacci Sequence PHP Practical: Code Example to Quickly Implement Fibonacci Sequence Mar 20, 2024 pm 02:24 PM

PHP Practice: Code Example to Quickly Implement the Fibonacci Sequence The Fibonacci Sequence is a very interesting and common sequence in mathematics. It is defined as follows: the first and second numbers are 0 and 1, and from the third Starting with numbers, each number is the sum of the previous two numbers. The first few numbers in the Fibonacci sequence are 0,1,1.2,3,5,8,13,21,...and so on. In PHP, we can generate the Fibonacci sequence through recursion and iteration. Below we will show these two

Basic tutorial: Create a Maven project using IDEA Basic tutorial: Create a Maven project using IDEA Feb 19, 2024 pm 04:43 PM

IDEA (IntelliJIDEA) is a powerful integrated development environment that can help developers develop various Java applications quickly and efficiently. In Java project development, using Maven as a project management tool can help us better manage dependent libraries, build projects, etc. This article will detail the basic steps on how to create a Maven project in IDEA, while providing specific code examples. Step 1: Open IDEA and create a new project Open IntelliJIDEA

PyCharm Tutorial: How to remove items in PyCharm? PyCharm Tutorial: How to remove items in PyCharm? Feb 24, 2024 pm 05:54 PM

PyCharm is a powerful Python integrated development environment (IDE) that provides rich functions to help developers write and manage Python projects more efficiently. In the process of developing projects using PyCharm, sometimes we need to delete some projects that are no longer needed to free up space or clean up the project list. This article will detail how to delete projects in PyCharm and provide specific code examples. How to delete a project Open PyCharm and enter the project list interface. In the project list,

Smooth build: How to correctly configure the Maven image address Smooth build: How to correctly configure the Maven image address Feb 20, 2024 pm 08:48 PM

Smooth build: How to correctly configure the Maven image address When using Maven to build a project, it is very important to configure the correct image address. Properly configuring the mirror address can speed up project construction and avoid problems such as network delays. This article will introduce how to correctly configure the Maven mirror address and give specific code examples. Why do you need to configure the Maven image address? Maven is a project management tool that can automatically build projects, manage dependencies, generate reports, etc. When building a project in Maven, usually

See all articles