yii2 asset里面的js和css写好了.怎么引入到页面上去

html-css016

yii2 asset里面的js和css写好了.怎么引入到页面上去,第1张

在页面里引入bootstrap的css和js文件的方法是通过modules的loader加载的。1、加载js文件:varpath=require('path')module.exports={context:path.resolve('js'),entry:"./index",output:{path:path.resolve('build/js/'),publicPath:'/public/assets/js/',filename:"bundle.js"}2、加载css文件:{test:/\.css$/,loaders:'style-loader!css-loader',exclude:/node_modules/}3、完整的写法如图:

公共js在布局文件引入,也就是main.php

单独view的js以及公共js都是使用$this->registerJs()

$this->registerJsFile()

$this->registerCss()

等方法引入

如果不行(上述方法一般可行,我在yii2就是这么用的),你可以使用use View(前面的命名空间忘记了,你找一下,里面有上所述的方法)

然后实例化$view = new View()然后$this->registerJs()等等