以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  requirejs 的 html 和css插件 引用参数的问题。  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=137170)

--  作者:ycwk
--  发布时间:2019/6/29 11:55:00
--  requirejs 的 html 和css插件 引用参数的问题。
首先是html加载插件里,为什么define里面有3个参数,而function只有2个参数?  不是要一一对应么?    
第二就是 css加载插件里的例子里的路径,不是要加 "css!" 吗?  为什么加的反而是"text!"   笔误还是?

RequireJS 插件

FoxWeb框架加入了几个RequireJS 插件,方便在组件中加载各种资源。

1、html加载插件

可以用来加载组件使用的html模板,模板内容放在一个独立的html文件中。需要在define中使用,在html文件路径前面加上【text! 】即可,如:


define([\'publib/loginUtils\', \'text!web_local/login/index.html\', \'css!web_local/login/index.css\'], function (util, template) {  
……  
一般回调函数需要有一个参数对应html模板内容,如上面的 template,这样就可以被vue组件的 template 属性使用了。

注意:引入html文件时需要加上扩展名html。


2、css加载插件

可以用来加载组件使用的css样式文件,模板内容放在一个独立的css文件中。需要在define中使用,在html文件路径前面加上【css! 】即可,如:

define([\'text!web_local/recyclist.html\'], function (template) {  
……  
[此贴子已经被作者于2019/6/29 11:56:53编辑过]

--  作者:有点蓝
--  发布时间:2019/6/29 14:31:00
--  
1、理论上都是一一对应的,但是如果不需要依赖模块返回值,function是可以不需要对应的参数的,特别是css的加载就是这样,css加载后就生效不需要再另外赋值,所以也就不需要返回值。

特别注意的是,如果不需要返回值的模块,必须定义到define模块数组的最后面,如:

define([\'publib/loginUtils\', \'text!web_local/login/index.html\', \'css!web_local/login/index.css\',\'css!web_local/login/index2.css\'], function (util, template)

如果放到中间,就不行了,如:

define([\'publib/loginUtils\', \'css!web_local/login/index.css\', \'text!web_local/login/index.html\',\'css!web_local/login/index2.css\'], function (util, template)

2、这个是帮助写错了,已更正