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

成都創(chuàng)新互聯(lián)成立與2013年,先為濮陽縣等服務建站,濮陽縣等地企業(yè),進行企業(yè)商務咨詢服務。為濮陽縣企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務解決您的所有建站問題。
和華為官方合作共建的鴻蒙技術社區(qū)
https://harmonyos./#zz
1.前言:
在第九篇文章購物車做好后,還忘記了一個至關重要的計算組件.在鴻蒙的組件中并沒有提供這樣一個計算功能的組件,因此我們今天來自定義一個,這個組件和之前做的購物車的小項目放在一起.直男缺乏美感,我們就模仿別人的就行:
2.組件介紹:
這里(以后也要用到)要用到一個標簽: .這個標簽會與表單用在一起,比如搜索框,登錄頁面等都會用到.input>.input>標簽規(guī)定用戶可輸入數(shù)據(jù)的輸入字段.type屬性規(guī)定 input元素的類型, 根據(jù)不同的 type 屬性,輸入字段有多種形態(tài).輸入字段可以是文本字段、復選框、密碼字段、單選按鈕、按鈕等等,今天所用到的是文本字段、復選框字段和密碼字段.
3.js業(yè)務邏輯層:
點擊事件onclick后,執(zhí)行+的操作可以沒有上限,但執(zhí)行-操作在實際應用(例如購物車商品的數(shù)量)當中一般是減1后就停止.這里我們做一個提示框,用來表示已經(jīng)減到最小。
- import prompt from '@system.prompt';
- export default {
- data: {
- title: 'World',
- num:1,
- },
- addnum(){
- ++this.num;
- },
- reducenum(){
- if(this.num>1){
- --this.num;
- }
- else{
- prompt.showToast({
- message:"對不起,商品至少為一件",
- duration:5000,
- })
- }
- }
- }
4.視圖層:
這里type的value可以是接收text,同樣也可以是number 讀者可以自行嘗試。
- +
5.css屬性設置:
- .container {
- width: 100%;
- height:1200px;
- display: flex;
- justify-content: center;
- align-items: center;
- }
- .countview{
- width: 300px;
- height: 120px;
- /**border: 3px solid red;**/
- display: flex;
- justify-content: center;
- align-items: center;
- border-radius: 100px;
- }
- .tv1{
- width: 70px;
- height: 70px;
- font-size: 60px;
- font-weight: bold;
- text-align: center;
- border:3px solid darkgray;
- border-radius: 35px;
- background-color: white;
- color:darkgrey ;
- }
- .tv2{
- width: 70px;
- height: 70px;
- font-size: 50px;
- font-weight: bold;
- text-align: center;
- border:4px solid #FFB964;
- border-radius: 35px;
- background-color: #FFB964;
- color: white;
- }
- .inputview{
- width: 200px;
- height: 100%;
- background-color: white;
- font-weight: bold;
- font-size: 50px;
- margin-left: 30px;
- }
6.效果呈現(xiàn):
這里用到的 input 的type屬性的文本字段和密碼字段.利用這兩個可以制作一個登錄頁面。
大家都知道在點擊輸入框時光標會閃爍,也即是需要獲取焦點.而獲取焦點的事件是 onfocus.取消焦點事件為onblur. 當我們點擊input的父容器時就獲得焦點,也就可以輸入字段,為了更直觀的看到獲取焦點成功,我設置了圖標的顏色,未獲取時圖標為灰色,獲取成功后為紅色.如下圖:
placeholder是用戶名密碼框未輸入內(nèi)容時,默認顯示的灰色文字。當未輸入字段時顯示,當在輸入字段獲得焦點時消失。
js業(yè)務邏輯層:
- export default {
- data: {
- title: 'World',
- flag:false,
- },
- click(){
- this.flag=true;
- },
- click1(){
- this.flag=false;
- }
- }
視圖層:
css屬性設置:
- .container {
- width: 100%;
- height: 1200px;
- display: flex;
- justify-content: center;
- align-items: center;
- flex-direction: column;
- }
- .one{
- width: 80%;
- height: 150px;
- background-color: rgb(242, 243, 247);
- border-radius: 100px;
- margin: 20px;
- display: flex;
- align-items: center;
- }
- .img1{width: 80px;
- height: 80px;
- }
- .input1{
- height: 100%;
- font-size: 50px;
- focus-color: rgb(109, 131, 170);
- }
- .bottom{
- width: 280px;
- height: 280px;
- border-radius: 140px;
- background-color: rgb(192, 192, 190);
- margin: 60px;
- font-size: 100px;
- }
- .but{
- display: flex;
- justify-content: center;
- }
歡迎讀者朋友訂閱我的專欄:[HarmonyOS開發(fā)從0到1]
https://harmonyos./column/35
想了解更多內(nèi)容,請訪問:
和華為官方合作共建的鴻蒙技術社區(qū)
https://harmonyos./#zz
文章標題:鴻蒙JS開發(fā)14自定義構建購物計算組件&表單組件
文章網(wǎng)址:http://m.fisionsoft.com.cn/article/dhjdici.html


咨詢
建站咨詢
