自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

鴻蒙JS開發(fā)14 自定義構(gòu)建購物計算組件&表單組件

開發(fā)
文章由鴻蒙社區(qū)產(chǎn)出,想要了解更多內(nèi)容請前往:51CTO和華為官方戰(zhàn)略合作共建的鴻蒙技術(shù)社區(qū)https://harmonyos.51cto.com/#zz

[[382445]]

想了解更多內(nèi)容,請訪問:

51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)

https://harmonyos.51cto.com/#zz

1.前言:

在第九篇文章購物車做好后,還忘記了一個至關(guān)重要的計算組件.在鴻蒙的組件中并沒有提供這樣一個計算功能的組件,因此我們今天來自定義一個,這個組件和之前做的購物車的小項目放在一起.直男缺乏美感,我們就模仿別人的就行: 

 2.組件介紹:

這里(以后也要用到)要用到一個標(biāo)簽:<input> .這個標(biāo)簽會與表單用在一起,比如搜索框,登錄頁面等都會用到<input>.input>.input>標(biāo)簽規(guī)定用戶可輸入數(shù)據(jù)的輸入字段.type屬性規(guī)定 input元素的類型, 根據(jù)不同的 type 屬性,輸入字段有多種形態(tài).輸入字段可以是文本字段、復(fù)選框、密碼字段、單選按鈕、按鈕等等,今天所用到的是文本字段、復(fù)選框字段和密碼字段.

3.js業(yè)務(wù)邏輯層:

點擊事件onclick后,執(zhí)行+的操作可以沒有上限,但執(zhí)行-操作在實際應(yīng)用(例如購物車商品的數(shù)量)當(dāng)中一般是減1后就停止.這里我們做一個提示框,用來表示已經(jīng)減到最小。

  1. import prompt from '@system.prompt'
  2. export default { 
  3.     data: { 
  4.         title: 'World'
  5.         num:1, 
  6.     }, 
  7.     addnum(){ 
  8.         ++this.num; 
  9.     }, 
  10.     reducenum(){ 
  11.         if(this.num>1){ 
  12.             --this.num; 
  13.         } 
  14.         else
  15.             prompt.showToast({ 
  16.                 message:"對不起,商品至少為一件"
  17.                 duration:5000, 
  18.             }) 
  19.         } 
  20.     } 

 4.視圖層:

這里type的value可以是接收text,同樣也可以是number 讀者可以自行嘗試。

  1. <div class="container"
  2.   <div class="countview"
  3.       <text class="tv1" onclick="reducenum">-</text> 
  4.           <input class="inputview" type="text" value="{{num}}"></input> 
  5.       <text class="tv2" onclick="addnum">+</text> 
  6.   </div> 
  7. </div> 

 5.css屬性設(shè)置:

  1. .container { 
  2.     width: 100%; 
  3.     height:1200px; 
  4.     display: flex; 
  5.     justify-content: center; 
  6.     align-items: center; 
  7. .countview{ 
  8.     width: 300px; 
  9.     height: 120px; 
  10.     /**border: 3px solid red;**/ 
  11.     display: flex; 
  12.     justify-content: center; 
  13.     align-items: center; 
  14.    border-radius: 100px; 
  15. .tv1{ 
  16.     width: 70px; 
  17.     height: 70px; 
  18.     font-size: 60px; 
  19.     font-weight: bold; 
  20.     text-align: center; 
  21.     border:3px solid darkgray; 
  22.     border-radius: 35px; 
  23.     background-color: white; 
  24.     color:darkgrey ; 
  25. .tv2{ 
  26.     width: 70px; 
  27.     height: 70px; 
  28.     font-size: 50px; 
  29.     font-weight: bold; 
  30.     text-align: center; 
  31.     border:4px solid #FFB964; 
  32.     border-radius: 35px; 
  33.     background-color: #FFB964; 
  34.     color: white; 
  35. .inputview{ 
  36.     width: 200px; 
  37.     height: 100%; 
  38.     background-color: white; 
  39.     font-weight: bold; 
  40.     font-size: 50px; 
  41.     margin-left: 30px; 

 6.效果呈現(xiàn):



這里用到的 input 的type屬性的文本字段和密碼字段.利用這兩個可以制作一個登錄頁面。

大家都知道在點擊輸入框時光標(biāo)會閃爍,也即是需要獲取焦點.而獲取焦點的事件是 onfocus.取消焦點事件為onblur. 當(dāng)我們點擊input的父容器時就獲得焦點,也就可以輸入字段,為了更直觀的看到獲取焦點成功,我設(shè)置了圖標(biāo)的顏色,未獲取時圖標(biāo)為灰色,獲取成功后為紅色.如下圖:


placeholder是用戶名密碼框未輸入內(nèi)容時,默認(rèn)顯示的灰色文字。當(dāng)未輸入字段時顯示,當(dāng)在輸入字段獲得焦點時消失。




js業(yè)務(wù)邏輯層:

  1. export default { 
  2.     data: { 
  3.         title: 'World'
  4.         flag:false
  5.     }, 
  6.     click(){ 
  7.         this.flag=true
  8.     }, 
  9.     click1(){ 
  10.         this.flag=false
  11.     } 

 視圖層:

  1. <div class="container"
  2.     <div class="one" onblur="click1" onfocus="click"
  3.         <image class="img1"src="{{flag?'common/qqs.png':'common/qqu.png'}}"></image> 
  4.         <input style="background-color:rgb(242, 243, 247);" class="input1" type="text" placeholder="QQ號/手機號/郵箱"> </input> 
  5.     </div> 
  6.     <div onblur="click1" class="one" onfocus="click"
  7.         <image class="img1"src="{{flag?'common/mimas.png':'common/mimau.png'}}"></image> 
  8.         <input  style="background-color:rgb(242, 243, 247);" class="input1" type="password" placeholder="輸入密碼"> </input> 
  9.     </div> 
  10.     <div class="but"
  11.         <button class="bottom">登錄</button> 
  12.     </div> 
  13. </div> 

 css屬性設(shè)置:

  1. .container { 
  2.  
  3.     width: 100%; 
  4.     height: 1200px; 
  5.     display: flex; 
  6.     justify-content: center; 
  7.     align-items: center; 
  8.     flex-direction: column
  9. .one{ 
  10.     width: 80%; 
  11.     height: 150px; 
  12.     background-color: rgb(242, 243, 247); 
  13.     border-radius: 100px; 
  14.     margin: 20px; 
  15.     display: flex; 
  16.     align-items: center; 
  17. .img1{width: 80px; 
  18.     height: 80px; 
  19. .input1{ 
  20.     height: 100%; 
  21.     font-size: 50px; 
  22.     focus-color: rgb(109, 131, 170); 
  23. .bottom{ 
  24.     width: 280px; 
  25.     height: 280px; 
  26.     border-radius: 140px; 
  27.     background-color: rgb(192, 192, 190); 
  28.     margin: 60px; 
  29.     font-size: 100px; 
  30.  
  31. .but{ 
  32.     display: flex; 
  33.     justify-content: center; 
  34.  

歡迎讀者朋友訂閱我的專欄:[HarmonyOS開發(fā)從0到1]

https://harmonyos.51cto.com/column/35

想了解更多內(nèi)容,請訪問:

51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)

https://harmonyos.51cto.com/#zz

 

責(zé)任編輯:jianghua 來源: 鴻蒙社區(qū)
相關(guān)推薦

2021-11-01 10:21:36

鴻蒙HarmonyOS應(yīng)用

2022-07-06 20:24:08

ArkUI計時組件

2022-10-25 15:12:24

自定義組件鴻蒙

2022-10-26 15:54:46

canvas組件鴻蒙

2009-06-24 15:13:36

自定義JSF組件

2022-04-24 15:17:56

鴻蒙操作系統(tǒng)

2021-09-15 10:19:15

鴻蒙HarmonyOS應(yīng)用

2022-02-16 16:09:12

鴻蒙游戲操作系統(tǒng)

2021-11-22 10:00:33

鴻蒙HarmonyOS應(yīng)用

2022-02-21 15:16:30

HarmonyOS鴻蒙操作系統(tǒng)

2009-06-25 14:53:35

自定義UI組件JSF框架

2022-12-07 08:56:27

SpringMVC核心組件

2022-03-01 16:09:06

OpenHarmon鴻蒙單選組件

2022-06-30 14:02:07

鴻蒙開發(fā)消息彈窗組件

2023-01-03 07:40:27

自定義滑塊組件

2022-07-15 16:45:35

slider滑塊組件鴻蒙

2022-09-16 15:34:32

CanvasArkUI

2022-02-16 15:25:31

JS代碼Canvas鴻蒙

2021-01-11 11:36:23

鴻蒙HarmonyOSApp開發(fā)

2021-12-24 15:46:23

鴻蒙HarmonyOS應(yīng)用
點贊
收藏

51CTO技術(shù)棧公眾號