php - 如何将 Laravel 与 Nuxt js 集成

标签 php laravel nuxt.js laravel-6.2 laravel-api

由于我使用 Laravel 作为后端,Nuxt js 作为前端,所以我无法同时使用两者,而且我也无法从前端调用任何 API。

所以如果有人知道的话请帮助我。

由于我使用以下详细信息来创建项目,但即使在 api.php 中编写代码,我也无法在 Nuxt js 中调用任何 API路由文件并创建受人尊敬的 Controller 和模型。

  1. Create a fresh project
`composer create-project --prefer-dist laravel/laravel <PROJECT NAME>`
  1. Now move to a respected directory using below command
`cd <PROJECT NAME>`
  1. Give permission to a storage folder on the root folder of the project
`sudo chmod -R 777 storage/`
  1. Create a database

  2. update .env

  3. Config Clear

php artisan config:clear

  1. Storage Link

php artisan storage::link

  1. Install Passport

composer require laravel/passport

  1. Create database structure by using a below command on the ROOT folder of the project

php artisan migrate

  1. For initial records, Please using below command

php artisan db:seed

  1. Install NPM

npm install

  1. Now install nuxt js

npx create-nuxt-app <PROJECT NAME>

  1. Now move to a respected directory using below command

cd <PROJECT NAME>

  1. To start the project we need to run below command

npm run build | npm run start/npm run dev

最佳答案

首先检查您的package.json文件,然后在您的依赖项中查看您是否有@nuxtjs/axios? 如果没有,请转到 https://axios.nuxtjs.org并安装它

也在 devDependency 的同一文件中检查您是否有 @nuxt/typescript-build,如果您不转到 https://typescript.nuxtjs.org并安装它

之后你可以简单地使用$axios发送和获取api请求

示例代码是:

async asyncData({ $axios }) {
  const test = await $axios.$get('your address')
  return { test }
}

更多信息可以在https://axios.nuxtjs.org/usage中找到

关于php - 如何将 Laravel 与 Nuxt js 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60070491/

相关文章:

php - 购物车表 - 反馈数据库设计

java - 当我尝试使用 HTTP 访问页面时,页面中的 PHP 未得到解析

javascript - NuxtJs 登录有效但未授权 401

typescript - @nuxt/i18n 安装/配置问题

php - 通过 Facebook Graph API 编辑评论

php - 从 MySQL 结果中删除相似结果的快速方法

Laravel Eloquent 地从 json 列的值中过滤

Laravel 限制基于客户/用户/租户的内容

jquery - 尝试在 axios 中显示 Laravel 验证错误

vue.js - 我是否必须修复最新 nuxt.js 的审核问题?