溫馨提示×

小程序怎么制作表格

楓吟
535
2021-03-23 18:26:36
欄目: 云計算

小程序制作表格的方法:1.創(chuàng)建微信小程序項目;2.在index.wxml文件中添加表格設(shè)計代碼;3.在index.wxss文件里添加表格樣式;4.在index.js文件中添加交互代碼;5.保存編輯的代碼并進行調(diào)試即可。

小程序怎么制作表格

具體操作步驟如下:

1、首先在創(chuàng)建一個微信小程序項目。

小程序怎么制作表格

2、在pages包下的index目錄中index.wxml文件里添加頁面設(shè)計代碼,從而實現(xiàn)表格設(shè)計。

<view class="table">

 <view class="tr bg-w">

  <view class="th">參數(shù)</view>

  <view class="th-2">內(nèi)容</view>

 </view>

 <block wx:for="{{listData}}" wx:key="{[code]}">

  <view class="tr bg-g" wx:if="{{index % 2 == 0}}">

   <view class="td-1" selectable="true">{{item.code}}</view>

   <view class="td-2" selectable="true" scroll-y="true" >

   <text class="th-text" style="overflow-y:auto;overflow-x:scroll" selectable="true">{{item.text}}</text>

   </view>

   <!--view class="td">{{item.type}}</view-->

  </view>

  <view class="tr bg-g2" wx:else>

   <view class="td-1" selectable="true">{{item.code}}</view>

   <view class="td-2" selectable="true" scroll-y="true" >

   <text class="th-text" style="overflow-y:auto;overflow-x:scroll" selectable="true">{{item.text}}</text>

   </view>

  </view>

 </block>

</view>

小程序怎么制作表格

3、在pages包下的index目錄中index.wxss文件里添加表格樣式代碼,美化表格設(shè)計。

.table {

  border: 2px solid darkgray;

  width: 89%;

  margin-top: 1rem;

  margin-right: 1rem;

  margin-left: 1rem;

 }

 .tr {

  display: flex;

  width: 100%;

  justify-content: center;

  height: 3rem;

  align-items: center;

 }

 .td {

   width:20%;

   justify-content: center;

   display: flex;

   text-align: center;

   border-right: 2px solid #ddd;

   height: 100%;

 }

 .td-1 {

   width:19%;

   justify-content: center;

   display: flex;

   text-align: center;

   border-right: 2px solid #ddd;

   height: 100%;

 }

 .td-2 {

   width:80%;

   justify-content: center;

   border-right: 2px solid #ddd;

   text-align: left;

   height: 100%;

   max-width: 100%;

   padding: 40rpx 0;

 }

 .bg-w{

  background: #afb4db;

 

 }

 .bg-g{

  background: #E6F3F9;

 }

 .bg-g2{

  background: #fff;

 }

 .th {

  width: 19%;

  justify-content: center;

  color: #fff;

  display: flex;

  height: 3rem;

  align-items: center;

  border-right: 2px solid #ddd;

 }

 .th-2 {

  width: 80%;

  justify-content: center;

  color: #fff;

  display: flex;

  height: 3rem;

  align-items: center;

  max-height: 3rem;

  max-width: 80%;

 }.th-text {

  width: 80%;

  justify-content: center;

  color: #000;

  display: block;

  height: 3rem;

  align-items: center;

  max-height: 3rem;

  max-width: 80%;

 }

小程序怎么制作表格

4、在pages包下的index目錄中index.js文件添加交互代碼。

var idinfolist = [

  { "code": "結(jié)果", "text": '' },

  { "code": "省", "text": '' },

  { "code": "市", "text": '' },

  { "code": "縣", "text": ''},

  { "code": "性別", "text": ''},

  { "code": "出生年月", "text": ''},

  { "code": "地址", "text": ''}

 ]

   

 Page({

  data: {

   listData: idinfolist,  

   inputValue: '', //用于顯示輸入語句

   searchinput: '', //用戶輸入的查詢語句

   }

  })

小程序怎么制作表格

5、最后保存編輯的代碼進行調(diào)試,保存快捷鍵【Ctrl+S】。

在開發(fā)工具左側(cè)即可看到設(shè)計效果。

小程序怎么制作表格

0