Laravel + Vue 2 如何运行 不同页面上的某些功能

Laravel + Vue 2 how to run certain functions on different pages

我很困惑,我有函数 getUsers()getCategories()(例如)来检索各自页面中的所有用户和类别 /admin/users & /admin/categories.

我有一个 table 用于加载用户,在另一个页面中有另一个 table 用于加载类别。

有人告诉我在 created 挂钩中使用它们,例如:

created: function() {
    this.getUsers();
    this.getCategories();
}

但是这会导致那些函数在同一个页面加载,我认为这是不必要的(也许当我有 100 万条记录时)。

所以我认为我需要的是 运行 this.getUsers() 当我在 /admin/usersthis.getCategories() 当我在 /admin/categories

Note: I am not using Vue-Router. Instead, I am using Laravel Routing

我该怎么办?

created: function() {
    var path = window.location.pathname;
    if(path === '/admin/users')
        this.getUsers();
    else if(path === '/admin/categories')
        this.getCategories();
}