您好,登錄后才能下訂單哦!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="./js/vue.js"></script>
</head>
<body>
<div id="app">
<ul>
<li v-for="item in arrayData">{{item}}</li>
</ul>
</div>
<script>
var vm = new Vue({
el: "#app",
data: () => ({
arrayData: ["e1", "e2", "e3", "e4"]
})
})
</script>
</body>
</html>
vue 下載到了本地 ,那么渲染頁面用了多長時間呢?
利用谷歌performance 可以看到
總共用了38.1ms
而用原生的js 達到同樣效果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="app">
<ul id="ul">
</ul>
</div>
<script>
var fragement = document.createDocumentFragment();
var arrayData = ["e1", "e2", "e3", "e4"];
for (var item in arrayData) {
var li = document.createElement('li');
li.innerText = arrayData[item];
fragement.appendChild(li);
}
document.getElementById('ul').appendChild(fragement);
</script>
</body>
</html>
用時多少呢?
僅僅只有 9.8ms 哦,
當然vue的優(yōu)勢在于mvvm的方式不能只通過這一項就說vue不好。
這個數(shù)據(jù)僅供參考
我們再來看下jquery
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="app">
<ul id="ul">
</ul>
</div>
<script src="./js/jquery3.4.1.js"></script>
<script>
$(function () {
var arrayData = ["e1", "e2", "e3", "e4"];
var html = ""
arrayData.forEach((item) => {
html += "<li>" + item + "</li>"
});
$("#ul").append(html);
});
</script>
</body>
</html>
11.8ms 可以說和原生js 很接近了
主要來看下react
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
//為了公平將資源下載到了本地
<!--
<script src="https://cdn.staticfile.org/react/16.4.0/umd/react.development.js"></script>
<script src="https://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js"></script>
<script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
-->
<script src="./js/react.16.8.6.js"></script>
<script src="./js/reactDom16.8.6.js"></script>
<!-- 生產(chǎn)環(huán)境中不建議使用 -->
<script src="./js/babel.min.js"></script>
</head>
<body>
<div id="example"></div>
<script type="text/babel">
var arrayData = ["e1", "e2", "e3", "e4"];
ReactDOM.render(
arrayData.map((item,key)=>{
return <li key={key}>{item}</li>
}),
document.getElementById('example')
);
</script>
</body>
</html>
164ms
比vue 的38ms幾乎多了4倍!
結(jié)論:
單從網(wǎng)頁引入的方式來看
耗費時間 是 react>vue>jquery>js 的
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。