小程序 : mustache语法 和 条件渲染 和 列表渲染
<!--pages/04_learn_wxml/index.wxml--> <h1>Mustache语法</h1> <view>{{ message }}</view> <view>{{ firstname + " " + lastname }}</view> <view>{{ date }}</view> <h1>条件判断</h1> <view wx:if="{{score > 90}}">优秀</view> <view wx:elif="{{score > 80}}">良好</view> <view wx:elif="{{score >= 60}}">及格</view> <view wx:else>不及格</view> <h1>hidden属性:v-show</h1> <view hidden>我是hidden的view</view> <button bindtap="onChangeTap">切换</button> <view hidden="{{isHidden}}">哈哈哈哈</view> <view wx:if="{{!isHidden}}">呵呵呵呵</view> <h1>for循环</h1> <view class="books"> <view wx:for="{{books}}" wx:key="id"> <!-- item: 每项内容, index: 每项索引 --> {{item.name}}-{{item.price}} </view> </view> <!-- 遍历数字 --> <view class="number"> <view wx:for="{{10}}" wx:key="*this"> {{ item }} </view> </view> <!-- 遍历字符串 --> <view class="str"> <view wx:for="coderwhy" wx:key="*this"> {{ item }} </view> </view> <!-- 4.2. 细节补充: block-item/index名称-key的使用 --> <view class="books"> <block wx:for="{{books}}" wx:key="id" wx:for-item="book" wx:for-index="i"> <view>{{ book.name }}-{{ book.price }}-{{ i }}</view> </block> </view>
// pages/04_learn_wxml/index.js Page({ data: { message: "Hello World", firstname: "kobe", lastname: "bryant", date: new Date().toLocaleDateString(), score: 10, isHidden: false, books: [ { id: 111, name: "代码大全", price: 98 }, { id: 112, name: "你不知道JS", price: 87 }, { id: 113, name: "JS高级设计", price: 76 }, ] }, onChangeTap() { this.setData({ isHidden: !this.data.isHidden }) } })
本文来自博客园,作者:杨建鑫,转载请注明原文链接:https://www.cnblogs.com/qd-lbxx/p/16665094.html