所以我发现自己在我的 vuex 操作中进行了不止一个 API 调用,这让我想知道什么是解决这种情况的最佳方法,多个 API 调用的最佳实践,让我们从我拥有的代码开始。
我有一个操作,我从不同的 API 端点(后端为 laravel)收集所有帖子和所有帖子类别,我确信必须有比我的做法更好的方法来解决这个问题:
fetchAllPosts ({ commit }) {
commit( 'SET_LOAD_STATUS', 1);
axios.get('/posts')
.then((response) => {
commit('FETCH_ALL_POSTS', response.data.posts )
commit( 'SET_LOAD_STATUS', 2 );
},
(error) => {
console.log(error);
commit( 'SET_LOAD_STATUS', 3 );
})
axios.get('/postcategories')
.then((response) => {
commit('FETCH_ALL_POSTCATEGORIES', response.data.postcategories )
commit( 'SET_LOAD_STATUS', 2 );
},
(error) => {
console.log(error);
commit( 'SET_LOAD_STATUS', 3 );
})
},Run Code Online (Sandbox Code Playgroud)
我能想到的第一个问题是,如果第一个 API 调用失败但第二个调用成功,我将获得 2 的加载状态(此处 2 等于成功)!
如果第一个和第二个 API 调用都正确获取数据,我只想处理提交,请帮助正在学习的人。
我希望能够在不同的选项卡/端口上同时提供多个 Laravel 应用程序,这样我就可以展示各种设计,遗憾的是当我运行 php artisan serve 时,我一次只能运行一个应用程序在端口 8000 上。
即使在更新到 Laravel 5.8 之后,也要形成文档:
Artisan Serve Improvements
In previous releases of Laravel, Artisan's serve command would serve your application on port 8000. If another serve command process was already listening on this port, an attempt to serve a second application via serve would fail. Beginning in Laravel 5.8, serve will now scan for available ports up to port 8009, allowing you to serve multiple applications at once.
Run Code Online (Sandbox Code Playgroud)
有什么我想念的吗?
我正在尝试从 laravel 的降价模板中删除标题部分,但它不起作用,我将文件发布到我的供应商文件夹和所有文件中。
这是我的消息组件:
@component('mail::layout')
{{-- Body --}}
{{ $slot }}
{{-- Subcopy --}}
@isset($subcopy)
@slot('subcopy')
@component('mail::subcopy')
{{ $subcopy }}
@endcomponent
@endslot
@endisset
{{-- Footer --}}
@slot('footer')
@component('mail::footer')
© {{ date('Y') }} {{ env('APP_NAME') }}.
@endcomponent
@endslot
@endcomponent
Run Code Online (Sandbox Code Playgroud)
还有我的布局文件:
{!! strip_tags($slot) !!}
@isset($subcopy)
{!! strip_tags($subcopy) !!}
@endisset
{!! strip_tags($footer) !!}
Run Code Online (Sandbox Code Playgroud)
有什么帮助吗?
另外,是否可以在不使用默认布局的情况下制作我自己的降价模板?我尝试将 Laravel Markdown 组件直接添加到我的邮件刀片 .php 文件中,但一切看起来都像垃圾且不居中。
提前致谢。
当我在 VPS 中运行 npm run prod 时,我一遍又一遍地遇到相同的错误。我的本地开发机器没有问题:
这是错误消息,我的应用程序是带有 Vue 的 Laravel 应用程序,我用它laravel-mix来编译我的资产,我的生产开发人员是带有 Ubuntu 和 LEMP 堆栈的 DigitalOcean VPS:
$ npm run prod
> @ prod /var/www/dtcburger.es
> npm run production
> @ production /var/www/dtcburger.es
> cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
internal/child_process.js:313
throw errnoException(err, 'spawn');
^
Error: spawn ENOMEM
at ChildProcess.spawn (internal/child_process.js:313:11)
at exports.spawn (child_process.js:508:9)
at Object.exports.fork (child_process.js:109:10)
at fork (/var/www/dtcburger.es/node_modules/worker-farm/lib/fork.js:17:36)
at Farm.startChild (/var/www/dtcburger.es/node_modules/worker-farm/lib/farm.js:106:16)
at Farm.processQueue (/var/www/dtcburger.es/node_modules/worker-farm/lib/farm.js:279:10)
at Farm.<anonymous> (/var/www/dtcburger.es/node_modules/worker-farm/lib/farm.js:97:21)
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout …Run Code Online (Sandbox Code Playgroud) 是否可以使用 Stripe PHP SDK 从 PaymentIntent 对象(与 Charges API 不同)获取卡的最后 4 位数字?
在我创建新帖子后的控制器中,我在帖子变量中返回新帖子。出于某种原因,我没有取回具有默认值的属性。我注意到,如果我将值设置为控制器中的某个值,它确实会返回有效负载中的属性。
public function create(Request $request)
{
$validatedData = $request->validate(PostValidator::$create);
$post = new Post();
$post->postcategory_id = $request->input('postcategoryid');
$post->user_id = $request->input('authorid');
$post->thumbnail = $this->uploadFile($request, 'thumbnail', config('app.defaultImage'));
$post->video = $request->input('video');
$post->slug = $this->slugify($request->input('title'));
$post->url = '/publicaciones/'.$this->slugify($request->input('title'));
$post->title = $request->input('title');
$post->body = $request->input('body');
$post->isVisible = false; //IF I DO THIS isVisible is returned in $post variable
$post->save();
$post->load(['postcategory','author']);
return response()->json([
'post' => $post,
]);
}
Run Code Online (Sandbox Code Playgroud) 我有一个从我的 PHP laravel 后端自动生成的 JSON 文件,它只是一个转换为 JSON 格式的数组,问题是我想要一个逐行的 JSON 文件,而不是这些丑陋的序列化数据......
我的 JSON 文件如下所示:
[{"cityName":"Toronto","provinceOrState":"Canada","country":"Canada"},{"cityName":"Montreal","provinceOrState":"Canada","country":"Canada"},{"cityName":"Calgary","provinceOrState":"Canada","country":"Canada"},{"cityName":"Ottawa","provinceOrState":"Canada","country":"Canada"},{"cityName":"Edmonton","provinceOrState":"Canada","country":"Canada"},{"cityName":"Mississauga","provinceOrState":"Canada","country":"Canada"},{"cityName":"North York",
Run Code Online (Sandbox Code Playgroud)
如果你将它粘贴到你的 IDE(我的是 Visual Studio Code)中,你会发现它看起来有多难看,因为它的语法高亮甚至不起作用......