微信小程序教程笔记2

假装没事ソ 提交于 2020-02-29 03:08:45

微信小程序的视图与渲染

  • 组件的基本使用
  • 数据的绑定
  • 渲染标签
  • 模板的使用
    在这里插入图片描述
    first.wxml
<include src="../templates/head"/>
first page
<button type="default" hover-class="other-button-hover"> default </button>
<button type="primary" bindtap="btnClick">{{btnText}}</button>
<view wx:if="{{show}}">{{text}}1</view>
<view wx:else>{{text}}2</view>
<text>this is text</text>
<text>{{show}}</text>
<view wx:for="{{news}}" wx:for-item="newsitem" wx:for-index="ix">
recycling content
{{ix}}-{{newsitem}}
</view>
<import src="../templates/rear"/>
<template is="rear2" data="{{text:'导入设置的内容。。。'}}"/>

fist.js

Page({

  /**
   * 页面的初始数据
   */
  data: {
    text:"this is text in js",
    btnText:"this is button text",
    show:"false",
    news:['a','b','c']
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  },
  btnClick : function(){
    console.log("button is clicked");
    var isShow=this.data.show;
    console.log("isShow:" + isShow);
    var newsdata=this.data.news;
    newsdata.shift()
    this.setData({ text: "this is a new content", show:!isShow,news:newsdata })
    
  }
})

<text>
this is head wxml;
</text>
<template name="rear1">
this is rear1 content template;
</template>

<template name="rear2">
this is rear2 content template;-{{text}}
</template>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!