小程序todo开发(腾讯云大学的笔记)

创建小程序

  1. 删除冗余文件,只留下index的页面。
  2. 创建git仓库
  3. 右键miniprogram文件夹,在终端中打开,输入npm i vant-weapp -S --production的命令。
  4. npm init -y生成一个page文件
  5. 详情中选择支持npm模块,在工具中选择创建npm模块

最终呈现效果:

  • 目录栏
    在这里插入图片描述

开始开发

  1. wxss设置按钮格式用npm包的样式"usingComponents": { "van-button":"vant-weapp/button" }
  2. wxml 中创建按钮
    n-button type="primary">按钮</van-button>显示结果
    在这里插入图片描述

版本管理

  1. 提交修改,只要创建了一个页面都要

创建表单

  1. wxml
<form bindsubmit="onSubmit">
<input name="title"></input>
<button form-type='submit' type="primary">提交</button>
</form>
  1. 创建名为todos的数据库集合

  2. js:创建实例,接受form事件,添加数据并且返回成功的信号。

onSubmit:function(event){
  todos.add({
    data:{
      title:event.detail.value.title
    }
  }).then(res=>{
    wx.showToast({
      title: 'success',
      icon:'success'
    })
  }

  )
}

编写界面

  1. 引入vant样式,设置为基本组件。
    在这里插入图片描述
  • 引入结果:

      "usingComponents": {
        "van-button":"vant-weapp/button",
        "van-cell": "vant-weapp/cell",
      "van-cell-group": "vant-weapp/cell-group"
      },
  1. 复制cell基础使用方式,拷贝代码至wxml。
    点击查看cell的基础用法
  2. 接收表单
    js:
  • 创建数据库实例

    const db=wx.cloud.database();
    const todos =db.collection('todos');
  • 设置关键字tasks。

  • 在这里插入图片描述

    wxml:

  • 可以使用view,或者block,建议使用block去渲染,因为不用重新生成。

  • {{tasks}}代表关键字

  • 是没有对称结构的

<van-cell-group>
<block wx:for ="{{tasks}}">
 <van-cell title="{{item.title}}"/>
</block>
</van-cell-group>
  1. 优化函数表达

    • 创建getdata函数,避免重复调用。

    • showloading显示正在加载。

    • 运用callback使得数据没有渲染完成之前不显示,增强使用人群体验。

    • 上拉刷新,下拉到底加载分屏

    • 将tasks设置为数组来支持concat的调用

       /**
         * 页面的初始数据
         */
        data: {
                tasks:[]
        },
      
        /**
         * 生命周期函数--监听页面加载
         */
        onLoad: function (options) {
          this.getData();
        
        },
      onReachBottom:function(){
      this.getData();
      
      },
      onPullDownRefresh:function(){
         this.getData(res=>{
      wx.stopPullDownRefresh();
       });
      },
      //callback是为了让刷新完成之后再给到页面才更新
       getData:function(callback){
         if(!callback)
         {
           callback=res=>{}
         }
         wx.showLoading(
           {title:'数据加载中'}
         )
        todos.skip(this.pageDate.skip).get().then(res =>{
          let oldData=this.data.tasks;
         this.setData(
            { tasks:oldData.concat(res.data)},res=>{
              this.pageDate.skip=this.pageDate.skip+20
              wx.hideLoading()
              callback();
            }
          )
      })
       },
       pageDate:{
         skip:0
       }

查看todos实现详情

创建todoinfor页面,在index.wxml创建一个navigator用来跳转到这个界面.

<van-cell-group>
<block wx:for ="{{tasks}}">
<navigator url="../todoinfor/todoinfor">
 <van-cell title="{{item.title}}"/>
 </navigator>
</block>
</van-cell-group>
<navigator url='../todoinfor/todoinfor?id={{item._id}}'>

更改使得页面id具有某种参数,新建编译模式,复制页面参数(使得每次打开的都是同一个页面进行开发)

利用options获得页面id

  onLoad: function (options) {
console.log(options);
  },

在todoinfor的js里设置数据库,并且获得数据。

const db=wx.cloud.database()
const todos=db.collection('todos')

pageData:{},
 data:{
     task:{},
 },
  
  onLoad: function (options) {

    this.pageData.id=options.id;
    todos.doc(options.id).get().then(res=>{
      this.setData({
        task:res.data
        })
    } )
  },

再使用cell显示

<van-cell-group>
  <van-cell title="{{task.title}}" border="{{ true }}"
  value="{{task.status==='yes'?'down':'undo'}}" />
</van-cell-group>

添加图片上传

在index.wxml中创建图标(app.json中的icon配置记得要加上)

<view class='plusBtn'>
<navigator url="../todo/todo">
<van-icon class="plusIcon" name="plus"/>
</navigator>
</view>
.plusBtn{
  position: fixed;
  z-index: 100;
  bottom: 100rpx;
  right:375rpx;
  background-color: #ff0000;
  border-radius: 100rpx;
  width:80rpx;
}
.plusIcon{
  font-size:80rpx;
}

就得到了极限丑陋的一个可以跳转到todos页面丑无比的图标

r>


.plusBtn{
position: fixed;
z-index: 100;
bottom: 100rpx;
right:375rpx;
background-color: #ff0000;
border-radius: 100rpx;
width:80rpx;
}
.plusIcon{
font-size:80rpx;
}


就得到了极限丑陋的一个可以跳转到todos页面丑无比的图标


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
160个项目开发实例,聊天项目,小游戏适和新手学习(项目采用GBK编码)。 import java.util.*; import java.io.*; import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing.*; class Gobang extends JFrame implements Runnable, ActionListener { final static int Player=1; final static int AI =-1; ClassLoader cl = this.getClass().getClassLoader(); Toolkit tk = Toolkit.getDefaultToolkit(); int length=14, game_state, winner, check, step; int grid[][] = new int[length][length]; int locX, locY /* 囱竚 */, count /* 硈囱计 */, x, y /* 既竚 */, displace_x=0, displace_y=0 /* 簿秖 */, direction; ArrayList steps = new ArrayList(); /* 癘魁囱˙ */ JPopupMenu control_menu = new JPopupMenu(); /* 龄匡虫 */ JMenuItem[] command = new JMenuItem[4]; String[] command_str={"囱", "郎", "弄郎", "秨"}; int[][] dir = { {-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1} }; boolean[] dir2 = new boolean[8]; boolean turn; String message; final JDialog dialog = new JDialog(this, "叫匡", true); Font font=new Font("new_font", Font.BOLD, 20); Grid grids[][] = new Grid[length][length]; Image white= tk.getImage(cl.getResource("res/white.png")); Image black= tk.getImage(cl.getResource("res/black.png")); Image title= tk.getImage(cl.getResource("res/title.png")); Image temp; JPanel boardPanel, bigpanel; JRadioButton[] choice = new JRadioButton[2]; final static int Start =0; final static int Select =1; final static int Playing =2; final static int End =3; final static int nil=-1; /* 礚よ */ final static int oblique_1 =0; /* オ */ final static int oblique_2 =1; /* オ */ final static int horizontal =2; /* 绢 */ final static int vertical=3; /*  */ Gobang() { super("き囱"); boardPanel = new JPanel(); boardPanel.setLayout(new GridLayout(length, length, 0, 0)); boardPanel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); for(int i=0; i<length; i++) for(int j=0; j<length; j++) {
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值