zoukankan      html  css  js  c++  java
  • 小程序学习笔记

    wxs

    // wxs/my-wxs.wxs
    var getMax = function(array) {
      var max = undefined;
      for (var i = 0; i < array.length; ++i) {
        max = max === undefined ?
          array[i] :
          (max >= array[i] ? max : array[i]);
      }
      return max;
    }
    
    module.exports = {
      getMax: getMax
    }
    

    wxml引入

    // pages/index.wxml
    // wxs src 为绝对路径
    <wxs src="../../wxs/my-wxs.wxs" module="info" />
    <view>{{info.getMax(array)}}</view>
    

    template

    <!--wxml-->
    <template name="staffName">
      <view>
        FirstName: {{firstName}}, LastName: {{lastName}}
      </view>
    </template>
    
    <template is="staffName" data="{{...staffA}}"></template>
    <template is="staffName" data="{{...staffB}}"></template>
    <template is="staffName" data="{{...staffC}}"></template>
    
    

    page.js

    Page({
      data: {
        staffA: {firstName: 'Hulk', lastName: 'Hu'},
        staffB: {firstName: 'Shang', lastName: 'You'},
        staffC: {firstName: 'Gideon', lastName: 'Lin'}
      }
    })
    

    component

    // custom-component.wxml
    
    <view>我是custom-component组件</view>
    
    

    在page.json 中注册

    // page.json
    {
      "navigationBarTitleText": "我是title",
      "usingComponents": {
        "custom-component": "../components/custom-component"
      }
    }
    

    在page.wxml中使用组件

    <custom-component/>
    
    

    事件传值

    // page.wxml
    <button class="add-btn" bind:tap="addCounter" data-addnum ="{{num}}">+</button>
    <button class="sub-btn" bind:tap="subCounter" data-subnum ="{{num}}">-</button>
    <view class="custome-counter">counter:{{counter}}</view>
    
    // page.js
     data: {
        counter:0,
        num:100
      
      }
    // tap事件
    addCounter(event) {
      console.log(event);
      this.setData({
        counter: this.data.counter + event.target.dataset.addnum
      })
    
    },
    subCounter(event) {
      console.log(event);
      this.setData({
        counter: this.data.counter - event.target.dataset.subnum
      })
    }
    
  • 相关阅读:
    uva 12034 Race
    计算机基础之计算机硬件软件数据结构
    Project Perfect让Swift在server端跑起来-Perfect in Visual Studio Code (四)
    关于自己定义转场动画,我都告诉你。
    Shell编程入门
    CODEVS 1029 遍历问题
    【VBA研究】工作表自己主动筛选模式检測
    卸载MySQL 5.0
    操作系统(二)进程控制
    前端面试题
  • 原文地址:https://www.cnblogs.com/bingziweb/p/13953976.html
Copyright © 2011-2022 走看看