Basics
1. CSS is only currentlyComponentskick in
2. The difference between v-if and v-show
3、r
o
u
t
e
and
route androuteandrouterThe difference
4、What are the two cores?
5、vueSeveral commonly used instructions
6. Common modifiers used by vue?
7. Can v-on bind multiple methods?
8. What is the role of key value in vue?
9. What are the computed properties of vue?
10. Single-page applications such as vue and their advantages and disadvantages
11. How to define the dynamic routing of vue-router? How to obtain the passed value
12. Differences between watch and computed
13. Why is data in the componentfunction
Extension
14. Understanding MVVM?
15. Several stages of the VUE life cycle
16. What is the vue life cycle?
17. What is the role of the vue life cycle?
18. What hooks will be triggered when the first page loading is launched?
19. In which cycle is the DOM rendering completed?
20. The principle of VUE implementing bidirectional data binding
21. Parameter transfer between VUE components
22. VUE routing implementation: hash mode and history mode
23. What is VUEX? How to use it? Which functional scenario uses it?
24. Understanding of keep-alive
25. What are the advantages and disadvantages of virtual DOM?
26. In-depth use of vue watch
27. vue andreactChoice
28. Detailed differences between mutation and action in vuex
29. What are the navigation guards in vue-router
30. Briefly describe diff in vuealgorithmprinciple
With the widespread application of VUE in enterprises, in addition to mastering a large number of interview questions, we also have to write codes that are easier to maintain, readable and more extensible in actual development; the following summarizes several common interview questions and techniques in development;
1. Common interview questions
Only work on the current component
Answer: Write scoped in the style tag, for example:
-Dif and v-show
Answer: Simple reply: v-if is rendered according to the conditions, v-show is the block or none of display;
Detailed comparison:
v-show is css switch, v-if is full destruction and recreation.
use
Use v-show when switching frequently, use v-if when changing less during runtime
v-if='false' v-if is conditional rendering, and will not be rendered when false
3.r
o
u
t
e
and
route androuteandThe difference between routers
answer:r
o
u
t
e
yes
“
road
Depend on
letter
interest
right
elephant
”
,
Bag
Above
p
a
t
h
,
p
a
r
a
m
s
,
h
a
s
h
,
q
u
e
r
y
,
f
u
l
l
P
a
t
h
,
m
a
t
c
h
e
d
,
n
a
m
e
wait
road
Depend on
letter
interest
Ginseng
number
.
and
route is a "routing information object", including path, params, hash, query, fullPath, matched, name and other routing information parameters. androuteyes“roadDepend onletterinterestrightelephant”,Bagincludepath,params,hash,query,fullPath,matched,namewaitroadDepend onletterinterestGinsengnumber。andThe router is a "routing instance" object that includes the route's jump method, hook function, etc.
4. Why is data in the component a function
Why must data in a component be a function, and then return an object, while in the new Vue instance, data can be directly an object?
Because components are used for reuse, objects in JS are reference relationships, so the scope is not isolated, and instances of new Vue will not be reused, so there is no problem of referencing objects.
Several stages of the life cycle
beforeCreate (before Creation) The data observation and initialization events have not started yet
Created (after creation) Complete data observation, attributes and methods operations, initialize events,e
l
Generic
sex
return
without
have
Show
Show
out
Come
b
e
f
o
r
e
M
o
u
n
t
(
load
enter
forward
)
exist
hang
load
open
Begin
Of
forward
quilt
Adjust
use
,
Mutually
close
of
r
e
n
d
e
r
Letter
number
head
Second-rate
quilt
Adjust
use
.
Reality
Example
already
over
become
by
Down
of
match
Set
:
Edited
Translation
Model
plate
,
Bundle
d
a
t
a
inside
noodle
of
number
According to
and
Model
plate
born
become
h
t
m
l
.
Note
meaning
this
hour
return
without
have
hang
load
h
t
m
l
arrive
Page
noodle
superior
.
m
o
u
n
t
e
d
(
load
enter
back
)
exist
e
l
quilt
new
Creation
establish
of
v
m
.
The el attribute has not been displayed beforeMount (before loading) is called before the mount starts, and the relevant render function is called for the first time. The instance has completed the following configuration: compile the template and generate html with the data and templates in data. Note that the html has not been mounted to the page at this time. mounted (after loading) newly created vm in el.elGenericsexreturnwithouthaveShowShowoutComebeforeMount(loadenterforward)existhangloadopenbeginningOfforwardquiltAdjustuse,MutuallycloseofrenderletternumberheadSecond-ratequiltAdjustuse。RealityexamplealreadyoverbecomebyDownofmatchSet:EditedTranslationmoldplate,Bundledatainsidenoodleofnumberaccording toandmoldplatebornbecomehtml。NotemeaningthishourreturnwithouthavehangloadhtmlarrivePagenoodlesuperior。mounted(loadenterback)existelquiltnewCreationestablishofvm.el replaces, mounts to the instance and calls it. The instance has completed the following configuration: Replace the DOM object pointed to by the el attribute with the html content compiled above. Complete the html rendering in the template tohtml pagemiddle. Ajax interaction is performed during this process.
beforeUpdate is called before data update, which occurs before virtual DOM re-rendering and patching. The state can be further changed in this hook without triggering an additional re-rendering process.
updated Called after virtual DOM rerendering and patching due to data changes. When called, the component DOM has been updated, so DOM-dependent operations can be performed. However, in most cases, changing the state during this period should be avoided, as this may result in an infinite loop of updates. This hook is not called during server-side rendering.
beforeDestroy is called before the instance is destroyed. The instance is still fully available.
destroyed (after destroyed) is called after the instance is destroyed. After being called, all event listeners will be removed and all sub-instances will be destroyed. This hook is not called during server-side rendering.
6. Understanding of keep-alive
Keep-alive is a built-in component in Vue that allows included components to retain state or avoid re-rendering.
After vue 2.1.0, keep-alive has added two new properties: include (including component cache) and exclude (excluding components are not cached, and the priority is greater than include).
Parameter explanation
include - String or regular expression, only components with matching names will be cached
exclude - String or regular expression, no component with a matching name will be cached
The include and exclude properties allow components to be cached conditionally. Both can be separated by "," strings, regular expressions,Array. When using regular or arrays, remember to use v-bind.
7. Detailed differences between mutation and action in vuex
1) Process sequence
"Relevant View—>Modify State" is split into two parts. The view triggers Action, and Action triggers Mutation.
2) Trigger method
The trigger of mutation is performed by
The triggering of the action is performed through
3) Role positioning
Based on the process sequence, the two play different roles.
Mutation: Focusing on modifying State is theoretically the only way to modify State.
Action: Business code, asynchronous request.
4) Limitations
Different roles have different restrictions.
Mutation: Mutation must be executed synchronously.
Action: Can be asynchronous, but cannot operate State directly.
2. Best practices for using Vue in enterprise practice
1. Always use :key in v-for
When data needs to be manipulated, using the key attribute with the v-for directive can keep the program constant and predictable.
This is necessary so that Vue can track component state and have a constant reference to different elements. Key is very useful when using animation or Vue conversion.
Without a key, Vue will just try to make the DOM as efficient as possible. This may mean that elements in v-for may be out of order or that their behavior is unpredictable. If we have a unique key reference to each element, we can better predict how exactly Vue applications will handle DOM operations.
2. Use short horizontal lines to naming in events
When issuing a custom event, it is best to use short horizontal lines to name it because in the parent component we use the same syntax to listen for the event.
So, to ensure consistency between our components and to make your code more readable, stick with short horizontal naming in both places.
3. Use camel to declare props and use short horizontal line naming in the template to access props
Best practices are just to follow the conventions in each language. In JS, camel declarations are standard, and in HTML, short horizontal line naming. So we use them accordingly.
Fortunately, Vue already provides conversions between camel declarations and short horizontal naming, so we don't have to worry about anything other than actually declaring them.
A function should always be returned
When declaring component data, the data option should always return a function. If the returned object is an object, the data will be shared among all instances of the component.
However, most of the time, our goal is to build reusable components, so we want each component to return a unique object. We do this by returning the data object in the function.
- Do not use v-if and v-for directives at the same time on the same element
To filter elements in an array, it is easy to use v-if and v-for at the same time.
The problem is that in Vue preferentially to use v-for directives rather than v-if directives. It loops through each element and then checks for the v-if condition.
There are several benefits to doing this:
More rendering efficiency because we don't traverse all elements
Filtered list will be reused only if the dependency changes
This writing helps separate component logic from the template, making components more readable
- Template expressions should have only basic JS expressions
It's natural to add as much inline functionality as possible to the template. But this makes our template less declarative and more complex, and makes the template very confusing.
To do this, let's take a look at another example of normalized strings in the Vue style guide to see how messy it is.
Basically, we want everything in the template to be intuitive and clear. To keep this, we should refactor the complex expressions into properly named component options.
Another benefit of separating complex expressions is that these values can be reused.
7. Do not call methods in "created" and "watch"
One of the mistakes that Vue developers often make is that they call methods in created and watch unnecessarily. The idea behind it is that we want to run the watch immediately after the component is initialized.
However, Vue provides a built-in solution for this, which is a Vue watch property we often forget.
All we have to do is reorganize the watch slightly and declare two properties:
1) handler (newVal, oldVal) - This is our watch method itself.
2) immediate: true- means that if it is declared in wacth, the handler method will be executed immediately. If it is false, it will be the same as our previous effect and will not be executed when binding.
Summary: In the actual development process, these tips are helpful to you, which can make our code easier to maintain, more extensible and readable. This is just a part of it. If you want to get more vue interview questions and practical development experience, you can add q group 902961830