微信小程序(四)

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";
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值