<view class="content"> <view class="hr"></view> <view class="bg"> <form bindsubmit="formSubmit" bindreset="formReset"> <view class="item"> <view class="name">联系人</view> <view class="value"> <input type="text" placeholder="收货人姓名" placeholder-class="holder" name="userName" value="{{userName}}" /> </view> </view> <view class="line"></view> <!-- <view class="item"> <view class="name">性别</view> <view class="value"> <radio-group class="radin-group" bindchange="radioChange" name="sex"> <radio value="0" checked="{{sex==0}}">先生</radio> <radio value="1" checked="{{sex==1}}">女士</radio> </radio-group> </view> </view> <view class="line"></view> --> <view class="item"> <view class="name">手机号码</view> <view class="value"> <input type="text" placeholder="联系您的电话" placeholder-class="holder" name="telNumber" value="{{telNumber}}" /> </view> </view> <view class="line"></view> <view class="item"> <view class="name">所在城市</view> <view class="value"> <picker mode="region" bindchange="bindRegionChange" value="{{region}}" custom-item="{{customItem}}" name="city"> <view class="picker"> {{region[0]}},{{region[1]}},{{region[2]}} </view> </picker> </view> </view> <!-- <view class="line"></view> <view class="item"> <view class="name">收货地址</view> <view class="value"> <input type="text" placeholder="选择收货地址" placeholder-class="holder" name="address" bindtap="chooseLocation" value="{{address}}" /> </view> </view> --> <view class="line"></view> <view class="item"> <view class="name">详细地址</view> <view class="value"> <input type="text" placeholder="请输入详细信息" placeholder-class="holder" name="detailInfo" value="{{detailInfo}}" /> </view> </view> <view class="line"></view> <button class="btn" form-type="submit">保存</button> <!-- <view class="tip">{{tip}}</view> --> </form> </view> </view>保存表单输入内容,并储存到缓存中
时间: 2023-07-19 20:49:47 浏览: 51
可以在表单提交事件中获取表单输入内容,然后使用`wx.setStorageSync(key, data)`方法将表单输入内容储存在缓存中。其中`key`为缓存的键名,`data`为要储存的数据。
例如:
```javascript
// 在表单提交事件中获取表单输入内容
const formData = e.detail.value;
// 将表单输入内容储存在缓存中
wx.setStorageSync('formData', formData);
```
需要注意的是,缓存中的数据仅在小程序关闭之前有效,小程序关闭后缓存中的数据会被清空。如果需要长期储存数据,可以考虑使用小程序提供的云存储服务。
相关问题
做个下面代码的样式:<template> <view> <view class="choose"> <view class="title">选择地址</view> <view class="user_info"> <view class="name-phone"><text>{{nickname}}</text><text>{{phone}}</text></view> <view class="address">{{address_detail}}</view> </view> </view> <!-- 订单信息 --> <view class="order-content"> <view class="product"> <view class="img"> <image :src="'http://localhost:3000/'+product.img" mode=""></image> </view> <view class="right-info"> <view class="product-name">黑糖拿铁</view> <view class="price-num"> <text>${{product.price}}</text> <text>x{{product.num}}</text> </view> </view> </view> <view class="num-allprice"> <text>共计{{product.num}}件商品</text> <text>订单金额 :{{product.allPrice}}元</text> </view> </view> <button @click="pay">立即结算</button> </view> </template>
以下是代码的样式:
```html
<template>
<view>
<view class="choose">
<view class="title">选择地址</view>
<view class="user_info">
<view class="name-phone">
<text>{{nickname}}</text>
<text>{{phone}}</text>
</view>
<view class="address">{{address_detail}}</view>
</view>
</view>
<!-- 订单信息 -->
<view class="order-content">
<view class="product">
<view class="img">
<image :src="'http://localhost:3000/'+product.img" mode=""></image>
</view>
<view class="right-info">
<view class="product-name">黑糖拿铁</view>
<view class="price-num">
<text>${{product.price}}</text>
<text>x{{product.num}}</text>
</view>
</view>
</view>
<view class="num-allprice">
<text>共计{{product.num}}件商品</text>
<text>订单金额 :{{product.allPrice}}元</text>
</view>
</view>
<button @click="pay">立即结算</button>
</view>
</template>
<style>
.choose {
/* 样式 */
}
.title {
/* 样式 */
}
.user_info {
/* 样式 */
}
.name-phone {
/* 样式 */
}
.address {
/* 样式 */
}
.order-content {
/* 样式 */
}
.product {
/* 样式 */
}
.img {
/* 样式 */
}
.right-info {
/* 样式 */
}
.product-name {
/* 样式 */
}
.price-num {
/* 样式 */
}
.num-allprice {
/* 样式 */
}
</style>
```
请注意,这里的样式只是示例,具体的样式需要根据实际情况进行调整。
优化这个布局<view class="box"> <uni-row class="demo-uni-row"> <uni-col :span="12"> <view class="boxnormal"> <text class="normaltext">正常气罐\n</text> <text class="normalSize">{{normalNumber}}</text> </view> </uni-col> <uni-col :span="12"> <view> <view class="warning"> <text class="warningtext">预警</text> <text class="warningSize">{{warningNumber}}</text> </view> <view class="error"> <text class="errortext">警告</text> <text class="errorSize">{{errorNumber}}</text> </view> </view> </uni-col> </uni-row> </view>
可以通过以下方式对这个布局进行优化:
1. 使用flex布局代替uni-row和uni-col布局,可以减少代码量,提高布局效率。
```
<view class="box">
<view class="boxnormal">
<text class="normaltext">正常气罐</text>
<text class="normalSize">{{normalNumber}}</text>
</view>
<view class="warning">
<text class="warningtext">预警</text>
<text class="warningSize">{{warningNumber}}</text>
</view>
<view class="error">
<text class="errortext">警告</text>
<text class="errorSize">{{errorNumber}}</text>
</view>
</view>
.box {
display: flex;
justify-content: space-between;
}
.boxnormal {
display: flex;
flex-direction: column;
align-items: center;
}
.warning, .error {
display: flex;
flex-direction: column;
align-items: center;
}
.warning {
background-color: #f5a623;
}
.error {
background-color: #f44336;
}
```
2. 将重复的样式封装成class,减少重复代码。
```
<view class="box">
<view class="boxnormal normal">
<text class="normaltext">正常气罐</text>
<text class="normalSize">{{normalNumber}}</text>
</view>
<view class="warning normalSize warningSize">预警 {{warningNumber}}</view>
<view class="error normalSize errorSize">警告 {{errorNumber}}</view>
</view>
.box {
display: flex;
justify-content: space-between;
}
.normal {
display: flex;
flex-direction: column;
align-items: center;
}
.warning {
background-color: #f5a623;
}
.error {
background-color: #f44336;
}
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)