Comments (2)
- 在
created
的时候,视图中的dom
并没有渲染出来,所以此时如果直接去操作dom
节点,无法找到相关的元素 - 在
mounted
中,由于此时dom
已经渲染出来了,所以可以直接操作dom
节点
一般情况下都放到 mounted
中,保证逻辑的统一性,因为生命周期是同步执行的, ajax
是异步执行的。
服务端渲染不支持
mounted
方法,所以在服务端渲染的情况下统一放到created
中
from fe_interview.
其实最好还是放在created的时候请求数据,请求完成之后把数据渲染到vnode中,然后mounted的时候只需要在渲染一次页面,放在mounted中会在请求数据之前先渲染一遍页面,然后vue检测到数据变化之后又重新渲染了部分变化的vnode,相比之下前者开销会更小
from fe_interview.
Related Issues (20)
- Vue中v-html会导致哪些问题?
- 如何理解MVVM原理?
- 为什么Vue采用异步渲染? HOT 1
- Vue父子组件生命周期的调用顺序?
- Vue中v-model的实现原理以及如何自定义v-model
- 谈谈你对keep-alive的理解 HOT 2
- 你知道Vue中的computed是怎么实现的吗? HOT 1
- 你是怎么理解JavaScript 中的执行上下文和执行栈的? HOT 2
- 说一下js中的词法作用域和动态作用域 HOT 2
- var缺陷以及为什么要引入let和const?
- 谈一下js中的作用域链 HOT 1
- 手写一个符合Promises/A+规范的promise HOT 1
- 说一下几种常见算法的时间复杂度 HOT 1
- 说一下浏览器缓存
- es module和commonjs的区别
- for、forEach、map的性能对比
- Webpack热更新的原理
- 简单说下webpack中的文件指纹策略 HOT 1
- 讲一下TCP三次握手、四次挥手过程及原理 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fe_interview.