Single file components are often used in actual development, so how to create a single file component? So in this article, we will briefly introduce the single-file component.
1. Create a single file component
1. Switch to the directory where you want to create the file. I am switching to the desktop directory. Of course, it is also You can switch according to your own needs. The command is cd directory/file name
2. Open cmd and enter npm config set registry https://www.php.cn/link/591d4b6b2ae94b362529d9dcbe8ea63f Switch/set to Taobao mirror. [Related recommendations: vuejs video tutorial, web front-end development]
Install global vue scaffolding (simple and convenient to use anywhere)npm install -g @vue/cli
See the following content to indicate successful installation
3. Use the vue create project name to create a project. After success, there will be a vue version to choose from (press the down arrow on the keyboard to switch). Here we choose Vue2
After the command is executed, if it looks like the picture below, it means the creation is successful (very considerate, the first line of blue code below is to switch to the directory where the creation was successful, and the second line is to run the vue project)
4. After successful creation, the project will come with a project as shown in the picture below (at this point, a vue project based on scaffolding is completed)
5. You can directly search for the file you just created, and then drag it directly into vscode (there are the following files). We can find the components folder under src, and there is a file named HelloWorld.vue in it. file, here is the code for the above picture
The following is a brief summary of the files in the project, file creation It's over, we have to know what this is for,
Curious friends will find a problem, that is, there is a vue file under node_module, which The file also contains various versions of vue, such as: vue.js , vue.runtime.js, etc. Stacking vue versions, let’s take a look at the differences between them
Second, about different versions of Vue
## The difference between #vue.js and vue.runtime.xxx.js
(1) .vue.js is complete Version of Vue, including: core function template parser. (2) . vue.runtime. xxx. js is the running version of Vue, which only contains core functions and does not have a template parser. Because vue.runtime.xxx.js does not have a template parser, the template configuration item cannot be used, and you need to userenderThe createElement function received by the function specifies the specific content.
Three, vue.config.js configuration file
Use vue inspect > output.js to view the Vue scaffolding default allocation.
Use vue.config.js to customize the scaffolding (the following is the configuration of vue.config.js for reference)
const { defineConfig } = require('@vue/cli-service') module.exports = defineConfig({ transpileDependencies: true, lintOnSave: false })
Four, ref attribute
1. It is used to register reference information for elements or sub-components. It can also be said to be used to replace id
2. Applied in htm1 What is obtained on the label is the real DOM element, and what is applied to the component label is the component instance object(VueComponent )
-
Usage: Mark:
....
orGet: this.$refs. xxx
##Five, configuration item props
Function:Let the component receive data from the outside
(1) Pass data:props: ["name"]The second way Method (restriction type)
props: { name:string, age:Number }The third method (restriction type, restriction necessity, specifying default value)
props :{ name : { type:String, //类型 required:true, //必要性 default:'老王' //默认值 } }Note: props are read-only, although it is read-only, it is still ok is modified, the bottom layer of Vue will detect the modification of props. If modifications are made, a warning will be issued. If the requirements really need to be modified, then copy the contents of props to the data, and then modify the contents of the data to achieve the requirements
6, mixin(mix)
##Function : You can extract the configuration shared by multiple components into a mix-in object Usage method:
The first step is to define the mix, for example: data(){ ....}, methods:{....}}, take out the methods or data configuration items of the component and put them in mixin.js. Here, the methods are put in mixin.js
The second step is to use mixin
Function: Used to enhance Vue
Essence: An object containing the insta1l method. The first parameter of install is Vue, and the second and subsequent parameters are the data passed by the plug-in user.
1. Define the plug-in: install = function (Vue, options) {//Add the global filter Vue.filter(....), you can also add other ones here, such as custom instructions, etc.
2. Use plug-in: Vue.use()
##8, scoped
The role of scoped styles: Make styles take effect locally to prevent conflicts.
Writing: Generally, scoped is only written in sub-components and does not need to be written in the app, because most of the styles in the app are basic styles. Every component can be used. If scoped is added, it will only take effect on this component and other components cannot use it(Learning video sharing: vuejs introductory tutorial, Basic programming video)
The above is the detailed content of An article briefly analyzing the single file component in Vue. For more information, please follow other related articles on the PHP Chinese website!

Netflix uses React as its front-end framework. 1) React's componentized development model and strong ecosystem are the main reasons why Netflix chose it. 2) Through componentization, Netflix splits complex interfaces into manageable chunks such as video players, recommendation lists and user comments. 3) React's virtual DOM and component life cycle optimizes rendering efficiency and user interaction management.

Netflix's choice in front-end technology mainly focuses on three aspects: performance optimization, scalability and user experience. 1. Performance optimization: Netflix chose React as the main framework and developed tools such as SpeedCurve and Boomerang to monitor and optimize the user experience. 2. Scalability: They adopt a micro front-end architecture, splitting applications into independent modules, improving development efficiency and system scalability. 3. User experience: Netflix uses the Material-UI component library to continuously optimize the interface through A/B testing and user feedback to ensure consistency and aesthetics.

Netflixusesacustomframeworkcalled"Gibbon"builtonReact,notReactorVuedirectly.1)TeamExperience:Choosebasedonfamiliarity.2)ProjectComplexity:Vueforsimplerprojects,Reactforcomplexones.3)CustomizationNeeds:Reactoffersmoreflexibility.4)Ecosystema

Netflix mainly considers performance, scalability, development efficiency, ecosystem, technical debt and maintenance costs in framework selection. 1. Performance and scalability: Java and SpringBoot are selected to efficiently process massive data and high concurrent requests. 2. Development efficiency and ecosystem: Use React to improve front-end development efficiency and utilize its rich ecosystem. 3. Technical debt and maintenance costs: Choose Node.js to build microservices to reduce maintenance costs and technical debt.

Netflix mainly uses React as the front-end framework, supplemented by Vue for specific functions. 1) React's componentization and virtual DOM improve the performance and development efficiency of Netflix applications. 2) Vue is used in Netflix's internal tools and small projects, and its flexibility and ease of use are key.

Vue.js is a progressive JavaScript framework suitable for building complex user interfaces. 1) Its core concepts include responsive data, componentization and virtual DOM. 2) In practical applications, it can be demonstrated by building Todo applications and integrating VueRouter. 3) When debugging, it is recommended to use VueDevtools and console.log. 4) Performance optimization can be achieved through v-if/v-show, list rendering optimization, asynchronous loading of components, etc.

Vue.js is suitable for small to medium-sized projects, while React is more suitable for large and complex applications. 1. Vue.js' responsive system automatically updates the DOM through dependency tracking, making it easy to manage data changes. 2.React adopts a one-way data flow, and data flows from the parent component to the child component, providing a clear data flow and an easy-to-debug structure.

Vue.js is suitable for small and medium-sized projects and fast iterations, while React is suitable for large and complex applications. 1) Vue.js is easy to use and is suitable for situations where the team is insufficient or the project scale is small. 2) React has a richer ecosystem and is suitable for projects with high performance and complex functional needs.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

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

Atom editor mac version download
The most popular open source editor

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

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