Laravel5.1将PHP转换为JavaScript
我正在使用Laracast/utilities将PHP转换为JavaScript。我已经通过composer安装了它 作曲家Laravel5.1将PHP转换为JavaScript,javascript,php,laravel,Javascript,Php,Laravel,我正在使用Laracast/utilities将PHP转换为JavaScript。我已经通过composer安装了它 作曲家 "require": { "laracasts/utilities": "~2.0" } 然后我在config/app.php中添加了提供者 app.php 'providers' => [ '...', 'Laracasts\Utilities\JavaScript\JavaScriptServiceProvider' ]
"require": {
"laracasts/utilities": "~2.0"
}
然后我在config/app.php中添加了提供者
app.php
'providers' => [
'...',
'Laracasts\Utilities\JavaScript\JavaScriptServiceProvider'
];
return [
/*
|--------------------------------------------------------------------------
| View to Bind JavaScript Vars To
|--------------------------------------------------------------------------
|
| Set this value to the name of the view (or partial) that
| you want to prepend all JavaScript variables to.
| This can be a single view, or an array of views.
| Example: 'footer' or ['footer', 'bottom']
|
*/
'bind_js_vars_to_this_view' => 'dashboard.master.dashboard_master',
/*
|--------------------------------------------------------------------------
| JavaScript Namespace
|--------------------------------------------------------------------------
|
| By default, we'll add variables to the global window object. However,
| it's recommended that you change this to some namespace - anything.
| That way, you can access vars, like "SomeNamespace.someVariable."
|
*/
'js_namespace' => 'pos'
];
在顶部的项目控制器中,我使用了JavaScript
这就是我使用它的方式
public function index()
{
// Get all projects
$projecten = Project::paginate(10);
JavaScript::put([
"total" => $projecten->total(),
"per_page" => $projecten->perPage(),
"current_page" => $projecten->currentPage(),
"last_page" => $projecten->lastPage()
]);
return view('dashboard.admin.project', compact('projecten'));
}
我还使用命令php-artisan-vendor:publish来配置它
并在javascript.php中更改以下内容
'providers' => [
'...',
'Laracasts\Utilities\JavaScript\JavaScriptServiceProvider'
];
return [
/*
|--------------------------------------------------------------------------
| View to Bind JavaScript Vars To
|--------------------------------------------------------------------------
|
| Set this value to the name of the view (or partial) that
| you want to prepend all JavaScript variables to.
| This can be a single view, or an array of views.
| Example: 'footer' or ['footer', 'bottom']
|
*/
'bind_js_vars_to_this_view' => 'dashboard.master.dashboard_master',
/*
|--------------------------------------------------------------------------
| JavaScript Namespace
|--------------------------------------------------------------------------
|
| By default, we'll add variables to the global window object. However,
| it's recommended that you change this to some namespace - anything.
| That way, you can access vars, like "SomeNamespace.someVariable."
|
*/
'js_namespace' => 'pos'
];
问题是我已经将bind_js_vars_to_this_视图设置为dashboard.master.dashboard_master这是我的仪表板母版页。如果我查看html,它会工作:
<html>
<head>
<script>window.pos = window.pos || {};pos.total = 75;pos.per_page = 10;pos.current_page = 1;pos.last_page = 8;</script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>POS</title>
<link media="all" type="text/css" rel="stylesheet" href="http://pos.dev:8000/css/bootstrap.css">
window.pos=window.pos | |{};pos.total=75;每页位置=10;位置当前页面=1;位置最后一页=8;
销售时点情报系统
但是is将js变量存储在顶部。而且,使用这种方法后,我的样式表也不能正常工作
如何在本页上使用下面的js变量。我认为这也解决了css的问题,但是如何?你能在主视图中插入仪表板的顶部吗?因为我在我的应用程序中做了完全相同的事情,我也在页面顶部获得了变量,但我没有遇到任何问题。奇怪的是,在你的html页面中,你会看到下面的部分。我将该部分完全放在我的页面顶部,甚至在标记上方。您的控制台中是否存在显示加载CSS文件问题的错误?您能否插入仪表板主视图的顶部?因为我在我的应用程序中做了完全相同的事情,我也在页面顶部获得了变量,但我没有遇到任何问题。奇怪的是,在你的html页面中,你会看到下面的部分。我把这个部分完全放在我的页面顶部,甚至在标签上面。你的控制台中有没有显示加载CSS文件时出现问题的错误?