[英]Best way to re-render v-for when I change my route in vue.js or without reload page manual
[英]Best way to check what page you're on in Vue.js
當我在汽車詳細信息頁面時,這些簡單的路線/URL
http://localhost:8080/car/1
我正在使用 vue2; 檢查我是否在car
頁上的最佳方法是什么?
會檢查 URL 的第一段,但我不確定這是否是最好的面向未來的方法。
我應該使用JS來檢測我是什么頁面嗎?
我應該使用 Vue 功能來訪問路由器 object 嗎?
為什么一個人會決定選擇一個而不是另一個?
您可以在routes
定義中為您的路由提供名稱,例如:
{
path: '/car/{id}',
name: 'car',
component: CarView
},
然后使用this.$route.name
訪問它,或者您可以解析this.$route.path
以使用 String object 方法獲取名稱
也許,嘗試使用: router.currentRoute.path
,其中路由器是:
import Router from "vue-router";
Vue.use(Router);
const routes = [
{ path: "/", component: Home },
{ path: "/test1", component: Test1 },
{ path: "/test2", component: Test2 }
];
const router = new Router({
routes
});
console.log('Current route: ', router.currentRoute.path);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.