Yii2框架加载了js文件返回错误

时间:2016-12-19 07:36:50

标签: php yii2 yii2-advanced-app

我使用yii2 AppAsset组件注册了js文件:

<?php

namespace backend\assets;

use yii\web\AssetBundle;

class DiyAsset extends AssetBundle
{
    public $basePath = '@webroot';
    public $baseUrl  = '@web';
    public $css = [
        //'css/diy.css',
    ];
    public $js = [
        'js/base.js',
    ];
    public $depends = [
        'yii\web\YiiAsset',
        'yii\bootstrap\BootstrapAsset',
    ];

}

js文件内容: the js file content

js文件加载成功,但chrome broswer显示错误:

show erros

expland erros

每个男孩都可以帮助我吗?

2 个答案:

答案 0 :(得分:1)

很可能您使用VirtualBox来运行Yii2应用程序。

如果是 - 请在Apache或Nginx配置中禁用load: function() { var iter = 0; // set up the updating of the chart each second var series = this.series[0], series2 = this.series[1]; myInterval = setInterval(function() { var len = Object.keys(BleedEnthalpy).length; var len2 = Object.keys(BypassRatio).length, x = new Date().getTime(); if (iter < len) { series.addPoint([x, BleedEnthalpy[iter]], false, true); series2.addPoint([x, BypassRatio[iter]], true, true); iter++; } else { clearInterval(myInterval); } }, 1000); } 。看看这个issue on GitHub

答案 1 :(得分:0)

从上面的讨论我可以猜测你的yii2生成的资产文件可能有问题,我试过重复你的错误但没有成功,

我之前也有这样的错误,当我复制粘贴以前的应用程序开始开发另一个应用程序时,我解决它的方法是删除生成的资源文件,因为yii2将重新运行应用程序再次运行文件

如果您使用的是高级模板

要删除的资产位于目录结构的根目录

_protected
assets //delete the contents in here but dont delete the folder assets
backend
themes
uploads
 ....etc

我希望这会有所帮助