This article introduces in detail how to use the vue.js scaffolding tool vue-cli to build a large single-page application. It is very practical. Friends in need can refer to the following
Prerequisites:
Familiar with using Javascript HTML5 css3.
Understand the ES2015 Module module (export, import, export-default).
Understand the basic knowledge of nodejs, common npm commands, and the use of npm script (npm is used for package management in the vue project).
Understand the webpack packaging tool (common configuration options and loader concepts). (webpack webpack.github.io/ is a module packaging tool. It treats each file in a bunch of files as a module, finds out their dependencies, and packages them into deployable static resources. The use of webpack is also Requires npm installation method).
Start the installation:
Use vue-cli to build a large single-page application: the scaffolding tool of vue.js.
Execute the following code to complete the basic construction of the project (webpack, installation of dependent packages, and generation of the basic directory have been configured).
# 全局安装 vue-cli $ npm install --global vue-cli # 创建一个基于 webpack 模板的新项目 $ vue init webpack my-project # 安装依赖,走你 $ cd my-project $ npm install $ npm run dev
Main directory:
├── build // Basic configuration of webpack, development environment configuration, production environment configuration
├── config // Path, port and reverse proxy Configuration
├── dist // Static resources packaged by webpack
├── node_modules // Dependency packages installed by npm
├── src // Front-end main file
│ ├── assets // Static resources
│ │ ├── font
│ │ ├── img
│ │ └── scss
│ ├── components // Single component
│ │ ├─ ─ xxx.vue // Single file component
│ ├── router // Routing configuration
│ ├── store // Global variable
│ ├── App.vue // App component
│ ├── main.js main entry file
├── static // static file
├── .babelrc // babel configuration items
├── .editorconfig // editor configuration items
├── .gitignore // Directory that will ignore syntax checking
├── index.html // Entry page
├── package.json // Project description and dependencies
package. json file description: project description and dependencies
1. scripts: some commands for compiling the project
Example: execute npm run dev, that is, execute the corresponding node build/dev-server in scripts. js.
2. dependencies: dependencies when the project is released
Example: execute npm install wx --save, that is, install the dependent module wx.
3. devDependencies: Dependencies during project development
Example: Execute npm install sass --save-dev, that is, install the dependent module sass.
Attachment: npm related instructions:
npm is a Node.js version management and dependency package management tool. It uses the node environment to install the dependency packages required for front-end construction projects.
The download speed of npm installation is too slow, use Taobao mirror cnpm install to install quickly. Setting method:
$ npm install -g cnpm --registry=https://registry.npm.taobao.org
Project loading process:
1. index.html page
The current construction project is SPA (Single Page Application), and the index.html page is the entry page, for meta and other related page configurations.
The page's
mounts the main component.2. main.js: main entry file
Note: Set in webpack.base.config-> entry: { app: './src/main.js'}
This file initializes the vue instance and introduces the corresponding module (you need to confirm the configuration and installation in package.json before importing). Attached is the main.js introduction and description:
import Vue from 'vue' //Introduce vue
import App from './App' //Introduce the main component App.vue
import router from './router' //Introduce routing configuration file
import axios from 'axios' //Introducing the network request tool axios
3. App.vue: main component
The main component is mounted in the index.html entry page, and in The main component is introduced in the main.js main entry file.
After creating other components (for example: /src/components/xxx.vue), they can be rendered in the current main component through routing configuration.
4. Routing configuration vue-router
Routing configuration: map components to routes (routes), and then tell vue-router where to render them
npm install vue-router
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
// 1. Define (routing) component: import (single file component in the current application).
import Home from '../components/Home.vue'
// 2. Define routes and create router instances, then pass `routes` configuration
// Each route should be mapped one components.
var router = {}
export default router = new Router({
routes: [
)
component: Home
}
]
})
// 3. Create and mount the root instance in the main.js main entry file.
// so that the entire application has routing functionality
new Vue({
router,
template: '
components: { App }
})
// Now, the application has been started!
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
How to use Vue-Router patterns and hooks (detailed tutorial)Using vue- in vue-cli Router builds the bottom navigation bar (detailed tutorial) How to use select to load data and select the default value in AngularJS?The above is the detailed content of How vue.js builds large single-page applications. For more information, please follow other related articles on the PHP Chinese website!

JavaScript core data types are consistent in browsers and Node.js, but are handled differently from the extra types. 1) The global object is window in the browser and global in Node.js. 2) Node.js' unique Buffer object, used to process binary data. 3) There are also differences in performance and time processing, and the code needs to be adjusted according to the environment.

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.


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

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

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

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
