javascript Yii2 BootstrapAsset 未加载 bootstrap.js
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30327781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Yii2 BootstrapAsset is not loading bootstrap.js
提问by ccdiego5
yii\bootstrap\BootstrapAsset
is not loading bootstrap.js
, and such elements as "modal" and others are not working.
yii\bootstrap\BootstrapAsset
未加载bootstrap.js
,并且诸如“模态”等元素不起作用。
class AppAsset extends AssetBundle {
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
/* theme */
'css/site.css',
/* jasny bootstrap */
'public/jasny/css/jasny-bootstrap.min.css',
/* font awesome */
'public/font-awesome-430/css/font-awesome.min.css',
/* font roboto */
'public/fonts/roboto/roboto.css',
/* Data Tables */
'public/datatables/extensions/integration/bootstrap/3/dataTables.bootstrap.css',
];
public $js = [
/* jasny bootstrap */
'public/jasny/js/jasny-bootstrap.min.js',
/* Data Tables */
'public/datatables/datajs.js',
'public/datatables/media/js/jquery.dataTables.min.js',
'public/datatables/extensions/integration/bootstrap/3/dataTables.bootstrap.js',
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}
Hereis screen of libraries, bootstrap.js
is missing there.
这是图书馆的屏幕,bootstrap.js
那里不见了。
采纳答案by mzk10k
You can try it:
你可以试试看:
class AppAsset extends AssetBundle{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/mystyle.css',
];
public $js = [
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapPluginAsset',
];
}
回答by arogachev
If you look at the content of BootstrapAsset
bundle, you will see that there is no bootstrap.js
:
如果您查看BootstrapAsset
bundle的内容,您会看到没有bootstrap.js
:
class BootstrapAsset extends AssetBundle
{
public $sourcePath = '@bower/bootstrap/dist';
public $css = [
'css/bootstrap.css',
];
}
For bootstrap.js
another asset bundle exists and it's called BootstrapPluginAsset
:
对于bootstrap.js
另一个资产包存在,它被称为BootstrapPluginAsset
:
class BootstrapPluginAsset extends AssetBundle
{
public $sourcePath = '@bower/bootstrap/dist';
public $js = [
'js/bootstrap.js',
];
public $depends = [
'yii\web\JqueryAsset',
'yii\bootstrap\BootstrapAsset',
];
}
The full class name with namespace is: yii\bootstrap\BootstrapPluginAsset
.
带命名空间的完整类名是:yii\bootstrap\BootstrapPluginAsset
。
It's included automatically when you use js dependent bootstrap widgets such as yii\bootstrap\Modal
, etc.
当您使用 js 依赖的引导程序小部件(例如yii\bootstrap\Modal
等)时,它会自动包含在内。
回答by Kalpesh Desai
when you add dependency
当您添加依赖项时
public $depends = [
'yii\bootstrap\BootstrapAsset',
];
its only add bootstrap css
它只添加引导 css
while you add
当你添加
public $depends = [
'yii\bootstrap\BootstrapPluginAsset',
];
its add bootstrap css as well as js
它添加引导 css 以及 js
回答by Roman Grinyov
You can do this in the main configuration file (config/web.php
):
您可以在主配置文件 ( config/web.php
) 中执行此操作:
'components' => [
'assetManager' => [
'bundles' => [
'yii\bootstrap\BootstrapAsset' => [
'js' => ['js/bootstrap.js'],
],
],
],
],
回答by Shamsi786
You can try this in AppAsset.php
你可以在 AppAsset.php 中试试这个
class AppAsset extends AssetBundle{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/mystyle.css',
];
public $js = [
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapPluginAsset',
];
}
and also change in you config/main.php
并且还更改了您的 config/main.php
'components' => [
'assetManager' => [
'bundles' => [
'yii\bootstrap\BootstrapAsset' => [
'js' => ['js/bootstrap.min.js'],
],
],
],
],
I have tried these steps that will solve my problem thats to all for your comment
我已经尝试了这些步骤来解决我的问题,请大家发表评论