Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
96 views
in Technique[技术] by (71.8m points)

php - Laravel error 8 SymfonyComponentHttpKernelExceptionNotFoundHttpException

Hi I have an API in laravel 8. I am trying to access 'localhost:8000/test' and I get error "Symfony Component HttpKernel Exception NotFoundHttpException". I have the front in vue and I access axios.

Configuration axios in front 'utils/axios.js':

import axios from 'axios';

axios.defaults.baseURL = 'http://localhost:8000/';
axios.defaults.timeout = 18000;

export default axios;

Index.vue (from where the request is made):

import axios from '../utils/axios';

export default {
  name: 'PageIndex',
  methods: {
    test() {
      axios.get('test')
        .then(() => {
          console.log('ok');
        })
        .catch((error) => {
          console.log(error);
        });
    },
  },
};

File 'routes/api.php' from laravel:

<?php
use IlluminateSupportFacadesRoute;

Route::get('test', 'TestController@index');

I've tried both Route::get('test', 'TestController@index'); and Route::get('/test', 'TestController@index'); and it still doesn't work ...

I don't know what else to look at.

A greeting and thanks for the answers :)

question from:https://stackoverflow.com/questions/65864472/laravel-error-8-symfony-component-httpkernel-exception-notfoundhttpexception

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As per the documentation, the routes defined in the routes/api.php file are reachable by prepending api before the URL, therefore, the axios.defaults.baseURL should be http://localhost:8000/api.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...