wxs
每个wxs都是一个独立的模块,类似于一个js文件。需要通过module.exports向外暴露。可以在别的wxs文件或者wxml文件中引入
var name = "ay";
var age = "18";
var method = function(obj){
return obj;
}
module.exports = {
name: name,
age: age,
method: method
};
//wxml中引入,调用wsx中的方法
<wxs src="../wxs/module.wxs" module="item" />
<view>{{item.name}}</view>
<view>{{item.age}}</view>
<view>{{item.method("this is a parameter")}}</view>
//在其他的wsx中引入,模块引入模块
var tools = require("../wxs/module.wxs");
console.log(tools.name)
wxml的外部引用
对于很多页面都是有相同的header和footer,代码是一致的,使用include引入相同的代码。include不会引入该wxml中的template和wxs
//header.wxml
<view>this is header</view>
//footer.wxml
<view>this is footer</view>
//body中引入
<include src="header.wxml"/>
<view>this is body</view>
<include src="footer.wxml"/>
wxss
同时作用多个样式,txt-css和txt-left,后面的会覆盖前面的。
<view class='txt-css txt-left' >this is body</view>
内联样式
<view style='color:{{color}}'>this is body</view>
wxss中导入其他wxss文件,相对路径
@import "test.wxss";