exports 關鍵字
.wxs 通過該屬性,可以對外共享本模塊的私有變量與函數
使用步驟
1. 在 .wxs后綴文件 exports定義參數
var foo = "'hello world' from comm.wxs"; var bar = function(d) { return d; } module.exports = { foo: foo, bar: bar };
2. 在 .wxml 后綴文件引入 .wxs文件,直接使用變量
<wxs src="./../tools.wxs" module="tools" /> <view> {{tools.msg}} </view> <view> {{tools.bar(tools.FOO)}} </view>
require 關鍵字
var foo = "'hello world' from tools.wxs";
var bar = function (d) { return d; }
module.exports = { FOO: foo, bar: bar, };
module.exports.msg = "some msg";
// /pages/logic.wxs
var tools = require("./tools.wxs");
console.log(tools.FOO);
console.log(tools.bar("logic.wxs"));
console.log(tools.msg);
<!-- /page/index/index.wxml -->
<wxs src="./../logic.wxs" module="logic" />
wxs標簽可直接在模版中使用

<wxs module="foo"> var some_msg = "hello world"; module.exports = { msg : some_msg, } </wxs> <view> {{foo.msg}} </view>
wxs 標簽的兩種屬性
modules 和 src 屬性

微信小程序常用的數據處理語句
if /else switch case for while
數據類型
- number : 數值
- string :字符串
- boolean:布爾值
- object:對象
- function:函數
- array : 數組
- date:日期
- regexp:正則
number 使用方法
使用方法
- toString
- toLocaleString
- valueOf
- toFixed
- toExponential(指數計數)
- toPrecision(方法可在對象的值超出指定位數時將其轉換為指數計數法)
string 使用方法
- toString
- valueOf
- charAt
- charCodeAt
- concat
- indexOf
- lastIndexOf
- localeCompare
- match
- replace
- search
- slice
- split
- substring
- toLowerCase
- toLocaleLowerCase
- toUpperCase
- toLocaleUpperCase
- trim
boolean 使用方法
布爾值只有兩個特定的值:true 和 false。
- valueOf
- toString
object 使用方法
- toString:返回字符串 "[object Object]"。
function 使用方法
- length: 傳遞給函數的參數個數。
- [index]: 通過 index 下標可以遍歷傳遞給函數的每個參數。
array使用方法
屬性
- constructor:返回字符串 "Array"。
- length
方法
- toString
- concat
- join
- pop
- push
- reverse
- shift
- slice
- sort
- splice
- unshift
- indexOf
- lastIndexOf
- every
- some
- forEach
- map
- filter
- reduce
- reduceRight
最后打開支付寶首頁搜“522158734”領紅包,領到大紅包的小伙伴趕緊使用哦!
O(∩_∩)O哈哈~