vue的hash值原理也是table切換實例代碼
更新時間:2020年12月14日 16:07:00 作者:然陳
這篇文章主要介紹了vue的hash值原理也是table切換,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
我希望大家敲一遍
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
.pages>div{display: none;}
</style>
</head>
<body>
<p>
<a href="#/" rel="external nofollow" >aaa</a>
<a href="#/about" rel="external nofollow" >bbb</a>
<a href="#/user" rel="external nofollow" >cccc</a>
</p>
<div class="pages">
<div id="home">首頁</div>
<div id="about">關(guān)于我的頁面</div>
<div class="user">用戶中心</div>
</div>
</body>
<script type="text/javascript">
//hash 和頁面一一對應起來
//router 配置
var router = [
{path:"/",component:document.getElementById("home")},
{path:"/about",component:document.getElementById("about")},
{path:"/user",component:document.querySelector(".user")},
]
// 默認hash
window.location.hash = "#/";
// 默認頁面
var currentView = router[0].component;
currentView.style.display="block";
window.onhashchange=()=>{
//通過判斷hash切換div頁面
console.log(location.hash);
//獲取hash值,不要井號
var hash = location.hash.slice(1);
router.forEach(item=>{
if(item.path==hash){
//先隱藏之前顯示的頁面
currentView.style.display = "none";
// 顯示對應的組件
item.component.style.display = "block";
//重新設(shè)置當前顯示的頁面是哪個div
currentView = item.component;
}
})
}
</script>
</html>



到此這篇關(guān)于vue的hash值原理也是table切換的文章就介紹到這了,更多相關(guān)vue hash原理內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue+element模態(tài)框中新增模態(tài)框和刪除功能
這篇文章主要介紹了vue+element模態(tài)框中新增模態(tài)框和刪除功能,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-06-06
公共Hooks封裝useTableData表格數(shù)據(jù)實例
這篇文章主要為大家介紹了公共Hooks封裝useTableData表格數(shù)據(jù)實例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-12-12
vxe-list?vue?如何實現(xiàn)下拉框的虛擬列表
這篇文章主要介紹了vxe-list?vue?如何實現(xiàn)下拉框的虛擬列表,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-06-06
利用Vue2.x開發(fā)實現(xiàn)JSON樹的方法
這篇文章主要給大家介紹了關(guān)于利用Vue2.x開發(fā)實現(xiàn)JSON樹的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧。2018-01-01

