search
HomeWeb Front-endJS TutorialKnowledge points about Vue interviews

This time I will bring you knowledge points about vue interviews. Friends who need it can pay attention to learn it. Let's follow the editor to take a look.

[Related recommendations: vue interview questions (2020)]

1.vue introduction

vue is a build user The framework of the interface. It is a lightweight mvv framework. Like Angular, it is the so-called two-way data binding, data-driven and component-based front-end development. It implements responsive data binding and combined view components through a simple API, which is easy to use and compact.

2. Install the vue-devtools plug-in to facilitate debugging vue in chrome. Configure whether vue-devtools is allowed to check the code to facilitate debugging. The production environment is set to false, vue.config.devtools = false;

vue.config.productionTip=false;Prevents starting production messages.

3. Commonly used instructions.

#v-model Two-way data binding, generally used for form elements.

v-for To perform loop operations on arrays or objects, use v-for instead of v-repeat

v-on is used to bind Set time, usage: v-on: time = 'function'

v-show/v-if is used to show or hide elements, v-show is implemented through display, v- if is created after each deletion

4. Events and attributes

v-on:click = "Abbreviation@click=""

$event event object, which includes event-related information, such as event source, time type, offset, etc.

Event bubbling, The native js method relies on event objects, while the vue method does not rely on event objects. @click.stop prevents events from bubbling;

Keyboard events: @keydown.13 or keydown. enter

Event modifier .stop Call event.stopPropagation();

##v-bind is used for attribute binding, usage v-bind :Attribute="" Example v-bind:src="" Abbreviation: src=""

5. Template

##vue.js Using HTML-based template syntax, the data template that binds dom to the vue instance is {{}} used to bind data and display it on the page

two-way binding v- model

Single binding {{}} may cause flickering problems, you can also use v-text v-html

Other instructions v -once data is bound once, v-pre does not mutate, and is displayed directly as it is

6. Filter

is used to filter model data. Processing and filtering of data pairs before display

Syntax: {{data | filter (parameter) |filter (parameter)}}

Built-in filters will be deleted after 2.0. If you use them, you can use third-party libraries such as lodash data-fns, date formatting, accounting.js, currency formatting and customization

7. Send ajax request

Vue itself does not support sending ajax requests. You need to use plug-ins such as vue-resource axios to implement it. It is recommended to use axios

axios is a promise-based http request client, used to send requests

Basic usage:

axios.get(url[,options]);  传参方式,url或者params传参
axios.post(url,data,[options]);

Note: When axios sends data by default, the data format is request payload, which is not the form data format used by our bed, so the parameters must be passed as key-value objects

, which cannot be Pass parameters in the form of json

Method of passing parameters: Splice the key-value pairs yourself, use transformrequst to convert the request data before sending the request, or use the qs module to convert

axios does not support cross-domain requests, you can use vue-resource to send cross-domain requests.

Send a request across domains: this.$http.get(url,[options]); this.$http.post(url,[options]);

8.vue life cycle

The process from creation to destruction of a vue instance becomes life cycle

9. Calculated properties

Computed properties are also used to store data. They have these two characteristics: the data can be logically processed and the data in the calculated properties can be monitored.

10.vue instance properties and methods

Properties vm.$el vm.$data vm.$options vm.$refs

Method vm.$mount() vm.$destroy vm.$nextTick(callback) vm.$set(object,key,vlaue) vm.$delete(object,key) vm. $watch(data,callback)

11, custom directive

custom global directive vue.directive (directive id, definition object)

12. Transition (animation)

vue provides a variety of different ways to apply the process when inserting updates or a dom. The essence is still using css animation,

Basic usage: Use the transition component and place the element to be animated in the modified component

Use it together with the third-party animation library animater.css

 <transition enter-active-class="animated fadeInLeft" leave-active-class="animated fadeOutRight">
        <p v-show="flag">显示内容</p>
    </transition>

13. Component

Components are one of the most powerful functions of vue. Components can wildly interact with html elements, encapsulate and reuse code, and components are custom element objects.

To define the component method, a> first create a component constructor, and then use the component constructor to create the component. b>Create directly

To reference the template, the component content is referenced in the template

componect :is="" Component, multiple components use the same hanging point, dynamic switching,

keep-alive cache component, avoid re-creation, efficiency comparison High

Usage method

Data transfer: parent-child component, in A component defines another component inside it, which is called a parent-child component.

       子组件只能在付组件中使用,默认情况下,子组件不能访问付组件数据。每个组件的作用域是独立的。

       组件间数据的通信:在调用组件时,绑定想要获取的付组件的数据,在子组件内部,使用props选项来生命获取

的数据,接收来自付组件的数据。例子:props:['msg']   props可以是数组,也可以是对象props:{} 允许配置高级设计比如类型判断

数据的校验,设置默认值 props:{messge:String,age:Number,name:{type:String,rquired:true,default:19,validator:function(){}}},对象做数组的默认值,

对象必须使用函数返回。

组件中的数据有三种形式:data  props computed 

付组件访问子组件数据方式:

a.在子组件中使用vm.$emit(事件名,数据) 出发一个自定义事件,事件名自定义

b.付组件在使用子组件的地方监听子组件出发事件,并在付组件中定义方法,用来获取数据

单项数据流:

props是单项绑定的,当付组件的属性变化时,将传导给子组件,但是不会反过来,而且不允许子组件直接

修改付组件中的数据

解决方案: a.如果子组件享把他作为局部数据来使用,可以将数据存入另一个变量在操作

b.如果子组件想修改数据并同步付组件,使用.sync  2.3开始支持,或者将付组件数据包装成udixiang,

然后在子组件中修改对象的属性。

非父子组件间通信:

可以通过一个空的vue实例来作为中央事件总线,用他来出发事件或监控事件

var Event = new Vue();    空对象

Event.$emit(事件名,数据);  发送数据

Event.$on(事件名,data=>{})  监听接收数据

slot内容分发:

用来获取组件中的元内容,就是组件标签中的内容;

获得指定标签内容可以给标签定义  slot="s1"   获取  

14.vue-router 路由

使用vue.js 开发spa 单页面应用,根绝不同url地址,显示不同内容,但实现在统一页面红,称单页面应用。

bower info vue-router    cnpm install vue-router -S

<p id="itany">
<p>
<!-- 使用router-link组件来定义导航,to属性指定链接url -->
<router-link to="/home">主页</router-link>
<router-link to="/news">新闻</router-link>
</p>
<p>
<!-- router-view用来显示路由内容 -->
<router-view></router-view>
</p>
</p>
<script>
//1.定义组件
var Home={
template:&#39;<h3 id="我是主页">我是主页</h3>&#39;
}
var News={
template:&#39;<h3 id="我是新闻">我是新闻</h3>&#39;
}
//2.配置路由
const routes=[
{path:&#39;/home&#39;,component:Home},
{path:&#39;/news/:username/:password&#39;&#39;,component:News},
{path:&#39;*&#39;,redirect:&#39;/home&#39;} //重定向
]
//3.创建路由实例
const router=new VueRouter({
routes, //简写,相当于routes:routes
// mode:&#39;history&#39;, //更改模式
linkActiveClass:&#39;active&#39; //更新活动链接的class类名
});
//4.创建根实例并将路由挂载到Vue实例上
new Vue({
el:&#39;#itany&#39;,
router //注入路由
});
</script>

知识点:

路由嵌套和参数传递:

a.查询字符串   login?name=tome&pwd=123     显示  {{$route.query}}

b。rest风格url       regist/alice/324    显示获取 {{$router.params}}

Route instance method:

router.push(); Add route, the function is the same as , both jump pages

router.replace() Replace route, the same function as above, no history records are generated

Single file component:

.vue file name The file component is a custom file format of vue.js. A .vue file is a separate poison arrow, which encapsulates a separate js css html

# in the file. ##.vue file consists of three parts template style script

vue-loader The browser itself does not recognize your .vue file, so it must load and parse the .vue file. In this case, vue-loaderleisi's loaderhaiyou

Many, html-loader css-loader style-loader babel-loader It should be noted that vue-loader is planned for webpack

webpack is a front-end resource modular loader and packaging tool,

Install related templates:

cnpm install vue-template-compiler -D //Precompiled template

Merge: cnpm install -D webpack webpack-dev-server vue-loader vue- html-loader css-loader vue-style-loader file-loader babel-loader babel-core babel-preset-env vue-template-compiler


Run the test: npm run dev

15. Scaffolding vue-cli

vue-cli is a vue scaffolding that can quickly build the project structure,

Commonly used project templates: webpack guarantees EsLint code specification checking and unit unit testing,

webpack-simple has no code checking and unit testing

browserify is also used more often

browserigy-simple

Install vue-cli and configure the vue command environment cnpm install vue-cli -g

vue --version

vue list
Initialize the project and generate the project template
Syntax: vue init template name project name
Enter the generated project directory and install the module package
cd vue -cli-demo
cnpm install
Run
npm run dev //Start the test service
npm run build //Package the project and output the dist directory. If the project is online, copy the dist directory to the server
Using webpack template
vue init webpack vue-cli-demo2
ESLint is a tool used to unify code specifications and styles, such as indentation, spaces, symbols, etc., and has strict requirements

16. Modular development

First create a project in a directory with vue init webpack-simple vue-cli-demo

Enter the directory cd vue-cli-demo cmpn install and then npm run dev Run test

cmpn install vue-router -S -S means production dependency;

Edit main.js import VueRouter form ''vue-router' vue.use(Vue/router ); After use, you can use

to edit app.vue globally and edit router.config,js

cnpm install axios -S

There are two ways to use axios:

a. In components that use axios, axios must be introduced import axios from 'axios' axios.get('url').then(resp ->{resp.data}); .catch(eorr->){}

b. Globally introduce import axios from 'axios' in main.js and add it to the vue prototype vue.prototype.$http=axios; Then other components can

vue.$http.get(); or this.$http.get();

Add events for custom components:

For example, if you customize a button vue registration, @click=send cannot be bound by default. Just write @click.ntaive=send like this.

17ui library element ui

is a ui The component library is a set of component libraries based on vue 2.0 provided by Ele.me. It can quickly develop URLs and improve efficiency

element ui pc terminal mintui mobile terminal official website element.eleme.io

cnpm install element-ui -S

npm run dev

Introduce and use this component in main.js import ElementUI from 'elemtn-ui' import element-ui/lib/eheme=default/ index.css

vue.use(ElementUI); This introduction method is to introduce all component content

Add loader in webpack.confgi.js test:/\.css$/, loader:'style-loader!css-loader'

cnpm instal style-loader -D Font font loader configuration

Restart webpack configuration changes

Dynamic style is to use less

Use less to install loader less less-loader configure test:/\.less$/,loader:less-loader specify style l ang=less must specify style

Customize global components:

Global component: You can use vue.use in main.js to enter the global introduction, and then use

to create it in other components. vue component, create index.js file import Login from './Login.vue'
export default {
install:function(Vue){
Vue .component('Login',Login);
}
}

Ordinary components: must be introduced every time they are used, such as axios

18.vuex state management mode

Uses centralized storage to manage the status of all components of the application. Simply put, centralized management of data is similar to redux in react, based on the flux front-end State management framework.

Basic usage: nmp install vuex -S

Create store.js file, vuex related configuration. Import in main.js, import store fomr './store.js main.js configure store options, subgroup this.$store

import vue fomr vue import vuex from vuex vue.use(vuex);

vuex core store is equivalent to a container. A store instance contains the following properties and methods:

getters Get properties

actions Define methods Actions, such as process judgment Asynchronous requests const action={method name (context){})} context object has comit dispatch state

commit means submission, the only way to modify data, conmit('add) submits a change called add

mutations Definition changes

var state= { count:6} //Create store object const store=new Vuex.Store{{state}}; vargetters ={count)(){return state.count}} export default store;

Edit app. js edit store, as a calculated attribute: computed:(){return this.$store.state.count};

Method 1 this.#store access Method 2 mapGetters mapActios access

mapGetter Get Attribute

mapActions Get method

Import auxiliary function import {mapGetter} from vuex

computed:mapGetters{('count')}

The above is the detailed content of Knowledge points about Vue interviews. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
From C/C   to JavaScript: How It All WorksFrom C/C to JavaScript: How It All WorksApr 14, 2025 am 12:05 AM

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

JavaScript Engines: Comparing ImplementationsJavaScript Engines: Comparing ImplementationsApr 13, 2025 am 12:05 AM

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

Beyond the Browser: JavaScript in the Real WorldBeyond the Browser: JavaScript in the Real WorldApr 12, 2025 am 12:06 AM

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

Building a Multi-Tenant SaaS Application with Next.js (Backend Integration)Building a Multi-Tenant SaaS Application with Next.js (Backend Integration)Apr 11, 2025 am 08:23 AM

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

How to Build a Multi-Tenant SaaS Application with Next.js (Frontend Integration)How to Build a Multi-Tenant SaaS Application with Next.js (Frontend Integration)Apr 11, 2025 am 08:22 AM

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript: Exploring the Versatility of a Web LanguageJavaScript: Exploring the Versatility of a Web LanguageApr 11, 2025 am 12:01 AM

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

The Evolution of JavaScript: Current Trends and Future ProspectsThe Evolution of JavaScript: Current Trends and Future ProspectsApr 10, 2025 am 09:33 AM

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

Demystifying JavaScript: What It Does and Why It MattersDemystifying JavaScript: What It Does and Why It MattersApr 09, 2025 am 12:07 AM

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

See all articles

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 agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists

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.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment