vue中 vue-router的路由的2种模式 (原生js模拟演示)

hash模式

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <a href="#a">a</a>
  <a href="#b">b</a>
  <a href="#c">c</a>
  <div id="app">

  </div>
</body>
<script>## 标题
  // 路由的hash 模式
  window.onhashchange = function (event) {
    console.log(event)
    console.log(location.hash)
    if(location.hash == '#a') {
      app.innerHTML = 'a视图'
    }
    if(location.hash == '#b') {
      app.innerHTML = 'b视图'
    }
    if(location.hash == '#c') {
      app.innerHTML = 'c视图'
    }
  }

  // 路由的history模式
  
</script>
</html>

history模式

发布了151 篇原创文章 · 获赞 1 · 访问量 1837

猜你喜欢

转载自blog.csdn.net/qq_45802159/article/details/104307565
今日推荐