我如何使用interceptor
的vue.js
?因此,在每个请求/响应之前,它应首先进入拦截器.我已经搜索了很多但是找不到关于它的好文档.
我想像这样使用JWTAuth:
(function (define) {
'use strict'
define(function (require) {
var interceptor
interceptor = require('rest/interceptor')
/**
* Authenticates the request using JWT Authentication
*
* @param {Client} [client] client to wrap
* @param {Object} config
*
* @returns {Client}
*/
return interceptor({
request: function (request, config) {
var token, headers
token = localStorage.getItem('jwt-token')
headers = request.headers || (request.headers = {})
if (token !== null && token !== 'undefined') {
headers.Authorization = token
}
return request
}, …
Run Code Online (Sandbox Code Playgroud) 在我的app.js
文件中,我构建了这个,所以我可以在vue中使用翻译:
Vue.prototype.trans = string => _.get(window.i18n, string);
Run Code Online (Sandbox Code Playgroud)
这在我的vue文件中运行良好:
{{ trans('translation.name') }}
Run Code Online (Sandbox Code Playgroud)
问题是我正在使用vuex
,我需要在模块中翻译一些东西:
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
export default {
namespaced: true,
state: {
page: 1,
criterias: [
{
name: this.trans('translation.name'),
filter: "life",
active: false
}
}
}
Run Code Online (Sandbox Code Playgroud)
但这里this.trans('translation.name')
没有用.我怎么能让这个工作?
现在我正在学习laravel,但我一直得到这个例子:
VerifyCsrfToken.php第53行中的TokenMismatchException:
我正在尝试创建一个迁移对象,然后将其写入数据库但由于某种原因它无法正常工作.这是我的route.php:
Route::get('/post/new',array(
'uses'=> 'blog@newPost',
'as' => 'newPost'
));
Route::post('/post/new', array (
'uses' => 'blog@createPost',
'as' => 'createPost'
));
Run Code Online (Sandbox Code Playgroud)
这是我的控制器名为blog.php:
使用Illuminate\Http\Request;
use App\Http\Requests;
use View;
use App\Http\Controllers\Controller;
use App\posts;
class blog extends Controller
{
public function newPost()
{
return View::make('new');
}
public function createPost()
{
$posts = new posts();
$posts->title = Input::get('title');
$posts->content = nl2br(Input::get('content'));
$posts->save();
}
}
Run Code Online (Sandbox Code Playgroud)
这是迁移:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePostsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/ …
Run Code Online (Sandbox Code Playgroud) 如何从公用文件夹中删除目录?现在我试试这个:
Storage::deleteDirectory($directory);
Run Code Online (Sandbox Code Playgroud)
但那看起来在存储文件夹中?
storage
如果目录存在,我将如何检查 Laravel ?
在文档中只记录了如何检查文件是否存在。
Storage::disk('local')->exists('file.jpg');
我今天第一次使用laravel服务容器.我知道在互联网上有很多东西可以找到,但我找不到解决方案.我正在尝试将接口绑定到类,但是当我这样做时,我收到错误:
目标[App\contracts\UploadService]不可实例化.
这是我的名为UploadServiceContainer的服务容器:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class UploadServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
$this->app->bind('App\Contracts\UploadService', 'App\Classes\upload\upload');
}
Run Code Online (Sandbox Code Playgroud)
}
我尝试在我的控制器中实例化它:
public function storeTicket(makeTicketRequest $request,UploadService $upload)
{ }
Run Code Online (Sandbox Code Playgroud)
我在app.php中注册了我的Serviceprovider.而且我也做到了:
php artisan clear-compiled
Run Code Online (Sandbox Code Playgroud) 下列:
在单元格图中找不到框架
https://github.com/dompdf/dompdf/issues/657
是互联网上众所周知的问题。但我找不到问题的解决方案。我正在尝试将我的 html 模板转换为 pdf。当我删除它时,<table>
它正在工作。否则它会抛出异常。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example 2</title>
<link rel="stylesheet" href="/administration/style.css" media="all" />
</head>
<body>
<header class="clearfix">
<div id="logo">
<img src="/administration/logo.png">
</div>
<div id="company">
<h2 class="name">Company Name</h2>
<div>455 Foggy Heights, AZ 85004, US</div>
<div>(602) 519-0450</div>
<div><a href="mailto:company@example.com">company@example.com</a></div>
</div>
</div>
</header>
<main>
<div id="details" class="clearfix">
<div id="client">
<div class="to">INVOICE TO:</div>
<h2 class="name">John Doe</h2>
<div class="address">796 Silver Harbour, TX 79273, US</div>
<div class="email"><a href="mailto:john@example.com">john@example.com</a></div>
</div>
<div id="invoice">
<h1>INVOICE 3-2-1</h1>
<div class="date">Date of …
Run Code Online (Sandbox Code Playgroud) 我有一个具有这种方法的子组件:
getSubscriptions () {
MessageService.subscriptions()
this.$parent.loading = true;
.then((data) => {
if (data.data.subscriptions == null) {
this.noSubscriptions = true;
} else {
this.subscriptions = data.data.subscriptions;
}
this.$parent.loading = false;
}).bind(this);
}
Run Code Online (Sandbox Code Playgroud)
所以我想在我的父组件中显示一个加载圈我像这样访问它:
this.$parent.loading
Run Code Online (Sandbox Code Playgroud)
(我的父组件有一个名为的数据属性loading
)
但是当我尝试使用gulp编译时,我会收到:
[14:52:56] Starting 'browserify'...
46 | }
47 |
> 48 | t this.$parent.loading = false;
| ^
49 | }).bind(this);
50 | },
51 |
{ SyntaxError: unknown: Unexpected token (48:28)
46 | }
47 |
> 48 | t this.$parent.loading = false; …
Run Code Online (Sandbox Code Playgroud) 我正在使用 Laravel 5.3,我正在尝试从作业中的用户中删除文件::
public function handle()
{
//Remove all files from a message
$this->files->map(function($file) {
$path = $file->getPath();
if(Storage::disk('s3')->exists($path))
{
Storage::disk('s3')->delete($path);
if(!Storage::disk('s3')->exists($path))
{
$attachment = File::find($file->id);
$attachment->delete();
}
}
});
}
Run Code Online (Sandbox Code Playgroud)
所以这适用于collections
. one
但是当我传递模型实例时如何让它发挥作用?
我正在尝试用荷兰语显示当前月份的完整名称。我试过这样:
\Carbon\Carbon::now()->subMonth()->format('F')
Run Code Online (Sandbox Code Playgroud)
但后来我看到的July
不是我想要的。我的应用服务提供者如下所示:
public function boot()
{
Carbon::setLocale('nl');
}
Run Code Online (Sandbox Code Playgroud)
知道我能做些什么来让它发挥作用吗?
(diffForHumans 工作正常)
laravel ×6
php ×6
javascript ×3
vue.js ×3
collections ×1
dompdf ×1
laravel-5.2 ×1
laravel-5.3 ×1
php-carbon ×1
prototype ×1
vuex ×1