⼩程序——个⼈信息添加数据库
1. js代码
// pages/myinfo/myinfo.js
Page({
/**
* 页⾯的初始数据
*/
data: {
sex:'男'
},
switchChange:function(e) {
if (e.detail.value) {
this.setData({ sex: '男' });
} else {
this.setData({ sex: '⼥' });
}
},
/**
* ⽣命周期函数--监听页⾯加载
*/
onLoad: function (options) {
},
/**
* ⽣命周期函数--监听页⾯初次渲染完成
*/
onReady: function () {
},
/**
* ⽣命周期函数--监听页⾯显⽰
*/
onShow: function () {
/**
* ⽣命周期函数--监听页⾯隐藏
*/
onHide: function () {
},
/**
* ⽣命周期函数--监听页⾯卸载
*/
onUnload: function () {
},
/**
* 页⾯相关事件处理函数--监听⽤户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页⾯上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* ⽤户点击右上⾓分享
*/
onShareAppMessage: function () {
},
//表单提交
formSubmit: function (e) {
url: ".......", //仅为⽰例,并⾮真实的接⼝地址
method: 'POST',
data: e.detail.value,
header: {
'content-type': 'application/x-www-form-urlencoded' // 默认值 },
success: (res) => {
//console.log(res.data)
){
wx.showToast({
title: res.data.msg,
icon: 'none',
duration: 2000
})
}else{
wx.showToast({
title: '添加成功',
icon: 'success',
duration: 2000
})
}
}
})
写文章的小程序
}
2.wxml 代码
<!--pages/myinfo/myinfo.wxml-->
<form bindsubmit="formSubmit">
<view class="weui-cells weui-cells_after-title">
<view class="weui-cell weui-cell_input">
<view class="weui-cell__hd">
<view class="weui-label">学号</view>
</view>
<view class="weui-cell__bd">
<input class="weui-input" name="no" placeholder="请输⼊学号" value='1635050640'/> </view>
</view>
<view class="weui-cell weui-cell_input">
<view class="weui-cell__hd">
<view class="weui-label">姓名</view>
</view>
<view class="weui-cell__bd">
<input class="weui-input" name="name" placeholder="请输⼊姓名" value='张翔' />
</view>
</view>
<view class="weui-cell weui-cell_input">
<view class="weui-cell__hd">
<view class="weui-label">性别</view>
</view>
<view class="weui-cell__bd">
<input class="weui-input" name="sex" value='{{sex}}'/>
</view>
<view class="weui-cell__ft">
<switch checked bindchange='switchChange'/>
</view>
</view>
<view class="weui-cell weui-cell_input">
<view class="weui-cell__hd">
<view class="weui-label">年龄</view>
</view>
<view class="weui-cell__bd">
<input class="weui-input" name="age" placeholder="请输⼊年龄" value='19' />
</view>
</view>
</view>
<view class="btn-area">
<button type='primary' formType="submit">提交</button>
</view>
</form>
3.在app.wxss引⼊⽂件weui.wxss
@import './weui.wxss';
4.weui.wxss代码
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论