大前端时代我们都习惯把模块尽可能的拆的比较细,这样方便维护起来比较方便,找起来也很容易。
微信官方已经给出了模板的引用,
<
template
name=
"title">
<
view
class=
'container'>
<
view
class=
'title'></
view
>
</
view
>
</
template
>
在需要的地方导入,引用
<
import
src=
"../template/index/block.wxml"
/
>
<
template
is=
"title"
/
>
wxss当中也只需要
@import "../
template/
index/
block.
wxss"
但在js逻辑中,看到很多人大多是通过module.exports的方式导出一个模块,然后在需要用的地方require某个模块,然后在某个生命周期函数中调用这个模块的某个方法。但这样模块之间的耦合仍然很大,并不能实现真正的拆分。熟悉vue的同学一定会了解mixin,但微信官方并没有给出方案,所以就自己写了一个,仅供参考。
建一个utils的文件夹,文件夹下建一个utils.js,内容如下
module.exports.mixinModule =
function() {
let tempModel = {}
let targetModel = {}
for (
let model