JS:CDN方式引入Vue-Router

代碼示例

<div id="app">
  <p>$route.name: {{$route.name}}</p>
  <p>$route.path: {{$route.path}}</p>
  <p>$route.query: {{$route.query}}</p>
</div>

<script src="/static/js/vue.js"></script>
<script src="/static/js/vue-router.js"></script>

<script>
  const router = new VueRouter({
    mode: "history", // 默認使用hash模式,url會出現#
  });

  const app = new Vue({
    router,
    el: "#app",
  });
</script>

顯示結果

$route.name:

$route.path: /demo.html

$route.query: { "id": "44", "name": "Tom" }

單頁面上使用vue-router,可以用來解析url上的參數

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章