微信小程序(四)

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中的方法

{{item.name}}
{{item.age}}
{{item.method("this is a parameter")}}
//在其他的wsx中引入,模块引入模块
var tools = require("../wxs/module.wxs");
console.log(tools.name)

wxml的外部引用

对于很多页面都是有相同的header和footer,代码是一致的,使用include引入相同的代码。include不会引入该wxml中的template和wxs

//header.wxml
this is header
//footer.wxml
this is footer

//body中引入

this is body

wxss

同时作用多个样式,txt-css和txt-left,后面的会覆盖前面的。

this is body

内联样式

this is body

wxss中导入其他wxss文件,相对路径

@import "test.wxss";

你可能感兴趣的:(微信小程序)