X
X
xcuube2019-07-30 09:40:22
Slim Framework
xcuube, 2019-07-30 09:40:22

How to connect Vue router and Slim?

Welcome all! I am writing an application on vue and slim, now I want to add routing on the client using Vue Router.
The essence of the problem is this: there is already written api on slim, all requests to it are transferred to this file, here is a super short example of it

$app = new \Slim\App;

    /* ---------  статистика  --------- */
    $app->group('/stat', function () {

        $this->get('/graphs', function ($request, $response, $args) {    

            return "some data";
        });

        $app->run();
    });

But when I send a request from vue to
methods: {
            fetchData () {
                this.$http.get('http://localhost:8080/api/stat/graphs', {
                }).then(response => {

                    console.log(response.data);
                });
            }
        }

I get a 404 error.
I think that Vue Router is trying to find a route to this address, but because it doesn't exist, an error occurs.
The question is, what is the problem and how to separate the routing on the client from the routing on the server?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nvdfxx, 2019-07-30
@xcuube

Do you have back and front running on the same port? Just usually 8080 is the front start port

S
serginhold, 2019-07-30
@serginhold

Judging by the code, Vue router is definitely not trying to find anything. Now you just make a get http request, and the correct address is /stat/graphs, without any /api at the beginning.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question