微信小程序开发学习笔记

这篇具有很好参考价值的文章主要介绍了微信小程序开发学习笔记。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

一、CSS相关笔记

1、css类选择器

微信小程序开发学习笔记

 2、html引用多个css类

微信小程序开发学习笔记

 3、指定color的方式

Color: red

Color: rgb(255, 99, 71)

Color: rgba(<red>, <green>, <blue>, <alpha>)

Color: #ff6347

4、背景相关

  • background-color:指定元素的背景色
  • opacity:指定元素的透明度,取值在0~1之间
  • background-image:指定元素的背景图像,在水平和垂直方向上都会重复图像
  • background-repeat:配合background-image使用,指定图像重复方向或者重复次数

background-image: url("gradient_bg.png");
background-repeat: repeat-x; 或者:background-repeat: no-repeat;

(1)background-position:指定背景图像的位置

background-position: right top;

(2)background-attachment:指定背景图像时滚动还是固定。

Fixed: 固定   scroll:滚动

(3)background属性简写:

background: #ffffff url("tree.png") no-repeat right top;

5、边框相关

  1. border-style:边框类型 solid / dotted等
  2. border-width:四个边框的宽度
  3. border-color:边框颜色
  4. border属性简写:(border-style必需)

border: 5px solid red;

  1. border-radius:圆角边框
  1. margin:外边距

包含:

Margin-top

Margin-right

Margin-bottom

Margin-left

  1. padding:内边距

包含:

Padding-top

Padding-right

Padding-bottom

Padding-left

  1. 所有HTML元素都可以视为方框,框模型如下:

微信小程序开发学习笔记

6、文本相关

  1. color:用于设置文本的颜色
  2. text-align:用于设置文本的水平对齐方式
  3. direction:用于更改元素的文本方向
  4. vertical-align:用于设置元素的垂直对齐方式
  5. text-decoration:用于设置或删除文本装饰

微信小程序开发学习笔记

文字间距

Text-indent:指定文本第一行的缩进

Letter-spacing:指定文本中字符之间的间距

Line-height:指定行之间的间距

  1. text-shadow:为文本添加阴影

7、字体相关

  1. font-family:规定文本的字体。该属性应包含多个字体名称作为“后备”系统。如果字体名称不止一个单词,则必须用引号引起来。
  2. font-style:用于指定斜体文本

normal:文字正常显示

italic:文本以斜体显示

  1. font-weight:指定字体的粗细
  2. font-size:设置文本的大小

8、列表相关

  1. list-style-type:指定列表项标记的类型

微信小程序开发学习笔记

  1. list-style-image:将图像指定为列表项标记
  2. list-style:列表的简写

list-style: square inside url("sqpurple.gif");

9、表格相关

  1. border-collapse:设置是否将表格边框折叠为单一边框

微信小程序开发学习笔记  微信小程序开发学习笔记

默认样式和单一边框样式

  1. 可悬停表格:

在<tr>元素上使用:hover选择器,以突出显示鼠标悬停时的表格行

  1. 响应式表格

在<table>元素周围添加带有overflow-x:auto的容器元素,以实现响应式效果。

如果屏幕太小而无法显示全部内容,则响应式表格会显示水平滚动条。

微信小程序开发学习笔记文章来源地址https://www.toymoban.com/news/detail-493435.html

二、from.wxml例子

<view class="content">
  <form bindsubmit="formSubmit" bindreset="formReset">
    <view class="section">
      <view class="section_title">性别</view>
      <radio-group name="sex">
        <label><radio value="male" checked/>男</label>
        <label><radio value="female" style="margin-left:20rpx;" />女</label>
      </radio-group>
    </view>

    <view class="section">
      <view class="section_title">选择目的地</view>
      <checkbox-group name="region">
        <label wx:for="{{regions}}">
          <checkbox value="{{item.name}}" checked="{{item.checked}}" />
          {{item.value}}
        </label>
      </checkbox-group>
    </view>

    <view class="section">
      <view class="section_title">地区选择器</view>
      <picker name="country" bindchange="bindPickerChange" value="{{index}}" range="{{countries}}">
        <view>当前选择:{{countries[index]}}</view>
      </picker>
    </view>

    <view class="section">
      <view class="section_title">日期选择器</view>
      <picker name="date" mode="date" value="{{date}}" start="2016-09-01" end="2018-09-01" bindchange="bindDateChange">
        <view>当前选择:{{date}}</view>
      </picker>
    </view>

    <view class="section">
      <view class="section_title">时间选择器</view>
      <picker name="time" mode="time" value="{{time}}" start="09:01" end="21:01" bindchange="bindTimeChange">
        <view>当前选择:{{time}}</view>
      </picker>
    </view>

    <view class="section">
      <view class="section_title">其他建议</view>
      <textarea name="suggest" style="height:100rpx;"
 placeholder="建议" value="{{suggest}}"/>
    </view>

    <view class="btn-area">
      <button formType="submit" type="primary">提交</button>
      <button formType="reset">重置</button>
    </view>
  </form>

  <view>
    <view class="section">
      <swiper indicator-dots="{{indicatorDots}}" vertical="{{vertical}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}">
        <block wx:for="{{background}}">
          <swiper-item>
            <image src="{{item}}"/>
          </swiper-item>
        </block>
      </swiper>
    </view>

    <view class="btn-area">
      <button type="default" bindtap="changeIndicatorDots">指示点</button>
      <button type="default" bindtap="changeVertical">{{vertical?'水平指示点':'垂直指示点'}}</button>
      <button type="default" bindtap="changeAutoplay">自动播放</button>
    </view>

    <slider bindchange="durationChange" value="{{duration}}" show-value min="500" max="2000" />
    <view class="section_title">页面切换间隔</view>
    <slider bindchange="intervalChange" value="{{interval}}" show-value min="2000" max="10000" />
    <view class="section_title">滑动动画时长</view>
  </view>

  <view class="btn-area">
    <view class="section_title">loading提示</view>
    <view>
      <loading hidden="{{hidden}}" bindtap="loadingtap">加载中,单击退出...</loading>
      <button type="default" bindtap="loadingTap1">事件loading</button>
    </view>
    <view>
      <loading hidden="{{hidden2}}">{{exit_time}}秒后退出...</loading>
      <button type="default" bindtap="loadingTap2">定时loading</button>
    </view>
  </view>

  <view class="btn-area">
    <view class="section_title">toast提示</view>
    <view>
      <toast hidden="{{hidden}}" bindchange="toast1Change">默认提示信息,1.5秒后关闭</toast>
      <button type="default" bindtap="toast1Tap">默认toast</button>
    </view>
    <view>
      <toast hidden="{{hidden2}}" duration="3000" bindchange="toast2Change">提示信息,3秒后关闭</toast>
      <button type="default" bindtap="toast2Tap">3秒关闭toast</button>
    </view>
  </view>

  <view class="btn-area">
    <view class="section_title">showtoast提示</view>
    <button type="default" bindtap="showtoast1Tap">默认loading</button>
    <button type="default" bindtap="showtoast2Tap">5秒关闭loading</button>
  </view>

  <view class="btn-area">
    <view class="section_title">modal模式对话框</view>
    <modal confirm-text="是" cancel-text="否" hidden="{{modalHidden}}" bindconfirm="modalConfirm" bindcancel="modalCancel">您是否真的要退出应用?</modal>
    <modal title="请选择" hidden="{{modalHidden2}}" no-cancel bindconfirm="modalChange2" bindcancel="modalChange2">
      <view class="section">
        <view class="section_title">请输入姓名</view>
        <input placeholder="姓名" />
      </view>
      <view class="section">
        <view class="section_title">想去的国家</view>
        <checkbox-group name="region">
          <label wx:for="{{regions}}">
            <checkbox value="{{item.name}}" checked="{{item.checked}}" />
              {{item.value}}
          </label>
        </checkbox-group>
      </view>

      <view class="section">
        <view class="section_title">出发日期</view>
        <picker mode="date" name="date1" value="{{date}}" start="2016-09-01" end="2018-09-01" bindchange="bindDateChange">
          <view>{{date}}</view>
        </picker>
      </view>

    </modal>
    <button type="default" bindtap="modalTap">退出应用</button>
    <button type="default" bindtap="modalTap2">可接收用户输入的对话框</button>
  </view>

  <view class="section">
    <view class="section_title">audio音频</view>
    <text>
      播放状态:{{audio.currentTime}}s / {{audio.duration}}s
    </text>
    <slider value="{{audio.percent}}" bindchange="sliderChange"></slider>
    <button type="primary" bindtap="playClick">
      <text wx:if="{{audio.isPlaying}}">点击暂停</text>
      <text wx:else>点击播放</text>
    </button>
  </view>

  <view class="section">
    <view class="section_title">video视频</view>
    <view style="text-align: center;">
      <video id="myVideo" src="{{video_src}}" binderror="videoErrorCallback" controls></video>
    </view>
  </view>

  <view class="section">
    <view class="section_title">获取手机号码信息</view>
    <input name="phone" placeholder="手机号码" bindinput="bindinput" />
    <button type="primary" bindtap="phoneTap">查询</button>
    <view wx:if="{{resCode == '200'}}">
      <view>电话号码:{{phone}}</view>
      <view>所属城市:{{city}}</view>
      <view>运营商:{{supplier}}</view>
    </view>
    <view wx:if="{{errMsg != ''}}">
      <view>错误信息:{{errNum}} - {{errMsg}}</view>
    </view>
  </view>


</view>

三、form.js例子

// pages/form/form.ts
const backgroundAudioManager = wx.getBackgroundAudioManager();

Page({
  /**
   * 页面的初始数据
   */
  data: {
    regions:[
      {name: 'Europe', value: '欧洲'},
      {name: 'america', value: '美洲', checked: 'true'},
      {name: 'africa', value: '非洲'},
      {name: 'other', value: '其他'}
    ],
    countries: ['中国', '美国', '巴西', '日本', '英国'],
    index: 0,
    time: '8:00',
    date: '2016-11-1',
    suggest: '',
    background: [
      '../../images/gao_1.jpeg',
      '../../images/gao_2.jpeg',
      '../../images/gao_3.jpeg',
      '../../images/gao_4.jpeg',
      '../../images/gao_5.jpeg'
    ],
    indicatorDots: true,
    vertical: false,
    autoplay: false,
    interval: 3000,
    duration: 1200,
    hidden: true,
    hidden2: true,
    exit_time: 5,
    modalHidden: true,
    modalHidden2: true,
    current:{
      poster: 'https://kekedj.com/uploadfiles/2021-10/202110071015218437.png',
      name: '雨蝶',
      author: '李翊君',
      src: 'https://www.xzmp3.com/down/4874bea05337.mp3'
    },
    audio:{
      isPlaying: true,
      currentTime: 0,
      duration: 0,
      isWarting: false
    },
    video_src: 'http://vjs.zencdn.net/v/oceans.mp4',
    html: "",
    phone: "",
    city: "",
    supplier: "",
    errMsg: '',
    resCode: '-2',
  },

  changeIndicatorDots: function(e: any){
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },

  changeVertical: function(e: any){
    this.setData({
      vertical: !this.data.vertical
    })
  },

  changeAutoplay: function(e: any){
    this.setData({
      autoplay: !this.data.autoplay
    })
  },

  intervalChange: function(e: any){
    this.setData({
      interval: e.detail.value
    })
  },

  durationChange: function(e: any){
    this.setData({
      duration: e.detail.value
    })
  },

  formSubmit: function(e: any){
    console.log('提交表单');
    console.log(e.detail.value);
  },

  formReset: function(e: any){
    console.log('form发生了reset事件');
  },

  bindPickerChange: function(e: any){
    console.log('picker发送选择改变')
    console.log(e.detail.value)
    this.setData({
      index: e.detail.value
    })
  },

  bindDateChange: function(e: any){
    console.log('日期发生改变')
    console.log(e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },

  bindTimeChange: function(e: any){
    console.log('时间发生改变')
    console.log(e.detail.value)
    this.setData({
      time: e.detail.value
    })
  },

  toast1Change: function(e: any){
    this.setData({
      hidden: true
    });
    console.log("第1个toast组件的change事件,这里可进行其他操作")
  },

  toast2Change: function(e: any){
    this.setData({
      hidden2: true
    });
    console.log("第2个toast组件的change事件,这里可进行其他操作")
  },

  toast1Tap: function(e: any){
    this.setData({
      hidden: false
    })
  },

  toast2Tap: function(e: any){
    this.setData({
      hidden2: false
    })
  },

  showtoast1Tap: function(){
    wx.showToast({
      title: "默认1.5秒关闭的loading消息提示框",
      icon: "loading",
      success: function(){
        console.log("success回调!")
      },
      complete: function(){
        console.log("complete回调!")
      }
    });
  },

  showtoast2Tap: function(){
    wx.showToast({
      title: "5秒关闭的loading消息提示框",
      icon: "loading",
      duration: 5000
    });
  },

  modalTap: function(e: any){
    this.setData({
      modalHidden: false
    })
  },

  modalConfirm: function(e: any){
    this.setData({
      modalHidden: true
    }),
    console.log(e)
  },

  modalCancel: function(e: any){
    this.setData({
      modalHidden: true
    }),
    console.log(e)
  },

  modalTap2: function(e: any){
    this.setData({
      modalHidden2: false
    })
  },

  modalChange2: function(e: any){
    this.setData({
      modalHidden2: true
    })
    console.log(e);
  },

  audioAction: {
    method: 'pause'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    var self = this;
    // 定时器(每秒执行1次)
    setInterval(function(){
      var h2 = self.data.hidden2;
      var t = self.data.exit_time;
      if(!h2){
        t = t - 1;
        if(t > 0){
          self.setData({
            exit_time: t
          })
        }
      }
    }, 1000);

    backgroundAudioManager.title = '测试音频';
    backgroundAudioManager.epname = '雨蝶';
    backgroundAudioManager.singer = '李翊君';
    backgroundAudioManager.coverImgUrl = 'https://kekedj.com/uploadfiles/2021-10/202110071015218437.png';
    backgroundAudioManager.src = 'https://www.xzmp3.com/down/4874bea05337.mp3';

    // backgroundAudioManager.onPlay(() => {
    //   console.info('开始播放');
    // });

    // 进度监听
    backgroundAudioManager.onTimeUpdate(() => {
      self.setData({
        'audio.currentTime': backgroundAudioManager.currentTime,
        'audio.duration': backgroundAudioManager.duration,
        'audio.percent': backgroundAudioManager.currentTime / backgroundAudioManager.duration * 100,
      });
    });
  },

  playClick: function(e: any){
    if(backgroundAudioManager.paused){
      backgroundAudioManager.play();
    }else{
      backgroundAudioManager.pause();
    }

    this.setData({
      'audio.isPlaying': !this.data.audio.isPlaying
    });
  },

  sliderChange: function(e: any){
    var val = e.detail.value;
    var second = backgroundAudioManager.duration * val / 100;
    backgroundAudioManager.seek(second);
  },

  loadingtap: function(e: any){
    this.setData({
      hidden: true
    })
  },

  loadingTap1: function(e: any){
    this.setData({
      hidden: false
    })
  },

  loadingTap2: function(e: any){
    this.setData({
      hidden2: false,
      exit_time: 5
    })

    var self = this
    // 定时器(5秒后执行)
    setTimeout(function(){
      self.setData({
        hidden2: true
      })
    }, 5000)

  },

  tapPlay: function(e: any){
    backgroundAudioManager.play();
    // backgroundAudioManager.onPlay(() => {
    //   console.log('开始播放')
    // })
    console.log('开始播放')
  },

  videoErrorCallback: function(e: any){
    console.log(e.detail.errMsg)
  },

  bindinput: function(e: any){
    this.setData({
      phone: e.detail.value,
      resCode: '-2'
    });
  },

  phoneTap: function(e: any){
    var phone = this.data.phone;

    if(phone != null && phone != ''){
      var self = this;
      wx.request({
        url: 'https://hcapi02.api.bdymkt.com/mobile',
        data: {'mobile': phone},
        header: {
          'Content-Type': 'application/json;charset=UTF-8',
          'X-Bce-Signature': 'AppCode/<自己的百度appcode信息>'
        },
        success: function(res){
          console.info(res)
          if(res.data.code == '200'){
            self.setData({
              errMsg: '',
              resCode: res.data.code,
              city: res.data.data.city,
              supplier: res.data.data.isp
            });
          }else{
            self.setData({
              errMsg: res.data.message,
              resCode: res.data.code
            })
          }
        }
      });
    }

  

  },

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

  },

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

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

  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})

到了这里,关于微信小程序开发学习笔记的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 微信小程序 | 小程序开发

    🖥️ 微信小程序专栏:小程序开发 初级知识 🧑‍💼 个人简介:一个不甘平庸的平凡人🍬 ✨ 个人主页:CoderHing的个人主页 🍀 格言: ☀️ 路漫漫其修远兮,吾将上下而求索☀️ 👉 你的一键三连是我更新的最大动力❤️ 目录 一、认识小程序开发 什么是小程序? 各个平台小

    2024年01月24日
    浏览(45)
  • 微信小程序学习笔记(五) 云开发

    微信云开发是微信团队联合腾讯云推出的专业的小程序开发服务。 开发者可以使用云开发快速开发小程序、小游戏、公众号网页等,并且原生打通微信开放能力。 开发者 无需搭建服务器 ,可免鉴权直接使用平台提供的 API 进行业务开发。 传统开发需要考虑 成本角度:维护

    2023年04月08日
    浏览(34)
  • 微信小程序开发 | 音乐小程序项目

    2023年04月20日
    浏览(29)
  • 微信小程序开发之微信小程序交互

    目录 一、小程序交互 前端: 1、先在登陆界面中编写代码 2、在前端中编写js代码 后端:           1、先导入依赖:           2、定义好配置文件           3、编写好实体类           4、将帮助类进行配置           5、编写mapper类           6、定义service层以及对应的

    2024年02月09日
    浏览(41)
  • 微信小程序开发---小程序的页面配置

    目录 一、小程序页面配置的作用 二、页面配置和全局配置的关系 三、页面配置中常用的配置项 在每个小程序中,每个页面都有自己的.json配置文件,用来对当前页面的窗口外观,页面效果进行配置。 小程序中,app.json中的windows节点,可以全局配置小程序中每个页面的窗口表

    2024年02月09日
    浏览(35)
  • 微信小程序开发教程(二)--上传小程序

    接上文,我们已经有一个小例子了。 在模拟器的位置,点击头像,会登录。 此时我们可以第一次尝试将我们的小程序进行上传。 点击下图箭头所指位置: 点击确定: 填写版本号和备注信息,选择上传: 在网页管理小程序上,选择上传,以下都选择红框所在位置: 填写相关

    2023年04月25日
    浏览(31)
  • 微信小程序 -- 小程序开发能力与拓展

    1. 获取用户头像 当小程序需要让用户完善个人资料时,我们可以通过微信提供的头像、昵称填写能力快速完善。如图: 想使用微信提供的头像填写能力,需要两步: 将 button 组件 open-type 的值设置为 chooseAvatar 当用户选择需要使用的头像之后,可以通过 bindchooseavatar 事件回调

    2024年04月15日
    浏览(48)
  • python做微信小程序开发,python怎么开发小程序

    大家好,小编来为大家解答以下问题,python做微信小程序开发,python怎么开发小程序,今天让我们一起来看看吧! 大家好,小编为大家解答用python编写一个小程序的问题。很多人还不知道如何用python做小软件,现在让我们一起来看看吧! 大家好,小编来为大家解答以下问题

    2024年03月12日
    浏览(54)
  • 【微信小程序开发零基础入门】——微信小程序入门

    学习小程序跟学习网页开发有什么不同 1.如何创建微信小程序项目 1.1 注册、登录、复制appId 注册:在 https://mp.weixin.qq.com/cgi-bin/wx 进行注册微信小程序开发账号 登录:在 https://mp.weixin.qq.com 登录小程序账号 复制appId: 在 \\\"开发\\\" 的 \\\"开发管理\\\" 的 \\\"开发设置\\\" 的 \\\"开发者ID\\\"中 1.2 下

    2024年02月03日
    浏览(44)
  • 【微信小程序开发】第 1 节 - 小程序简介

             欢迎来到博主 Apeiron 的博客,祝您旅程愉快 ! 时止则止,时行则行。动静不失其时,其道光明。 目录 1、缘起 2、小程序与普通网页开发的区别 3、API 简介 4、总结         在日常生活中,我们几乎每天都在使用微信小程序,那么,这个微信小程序到底是怎么

    2024年02月07日
    浏览(29)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包