1. 程式人生 > >vue如何獲取當前頁面的url

vue如何獲取當前頁面的url

如果你使用 vue-router 文件在這裡 路由資訊物件的屬性

const routes = [
  {path : '/portfolio/:year/review', component : Portfolio }
];

這個樣子獲取

this.$route.params.year
this.$route.query.id

 或者(未嘗試)

clipboard.png

還有一種經常用的方式

當前頁面
完整url可以用 window.location.href
路由路徑可以用 this.$route.path
路由路徑引數 this.$route.params