由于我使用 Laravel 作为后端,Nuxt js 作为前端,所以我无法同时使用两者,而且我也无法从前端调用任何 API。
所以如果有人知道的话请帮助我。
由于我使用以下详细信息来创建项目,但即使在 api.php
中编写代码,我也无法在 Nuxt js 中调用任何 API路由文件并创建受人尊敬的 Controller 和模型。
- Create a fresh project
`composer create-project --prefer-dist laravel/laravel <PROJECT NAME>`
- Now move to a respected directory using below command
`cd <PROJECT NAME>`
- Give permission to a storage folder on the root folder of the project
`sudo chmod -R 777 storage/`
Create a database
update .env
Config Clear
php artisan config:clear
- Storage Link
php artisan storage::link
- Install Passport
composer require laravel/passport
- Create database structure by using a below command on the ROOT folder of the project
php artisan migrate
- For initial records, Please using below command
php artisan db:seed
- Install NPM
npm install
- Now install nuxt js
npx create-nuxt-app <PROJECT NAME>
- Now move to a respected directory using below command
cd <PROJECT NAME>
- 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/