鴻蒙OS 添加留言區(qū)域

2020-09-18 13:41 更新

留言框的功能為:用戶輸入留言后點擊完成,留言區(qū)域即顯示留言內(nèi)容;用戶點擊右側(cè)的刪除按鈕可刪除當(dāng)前留言內(nèi)容重新輸入。

留言區(qū)域由 div、text、input 關(guān)聯(lián) click 事件實現(xiàn)。開發(fā)者可以使用 input 組件實現(xiàn)輸入留言的部分,使用 text 組件實現(xiàn)留言完成部分,使用 commentText 的狀態(tài)標(biāo)記此時顯示的組件(通過 if 屬性控制)。在包含文本“完成”和“刪除”的 text 組件中關(guān)聯(lián) click 事件,更新 commentText 狀態(tài)和 inputValue 的內(nèi)容。具體的實現(xiàn)示例如下:

<!-- xxx.hml -->
<div class="container">
  <div class="left-container">
    <text class="comment-title">Comment</text>
    <div if="{{!commentText}}">
      <input class="comment" value="{{inputValue}}" onchange="updateValue()"></input>
      <text class="comment-key" onclick="update" focusable="true">Done</text>
    </div>
    <div if="{{commentText}}">
      <text class="comment-text" focusable="true">{{inputValue}}</text>
      <text class="comment-key" onclick="update" focusable="true">Delete</text>
    </div>
  </div>
</div>

/* xxx.css */
.container {
  margin-top: 24px;
  background-color: #ffffff;
}
.left-container {
  flex-direction: column;
  margin-left: 48px;
  width: 460px;
}
.comment-title {
  font-size: 24px;
  color: #1a1a1a;
  font-weight: bold;
  margin-top: 10px;
  margin-bottom: 10px;
}
.comment-key {
  width: 74px;
  height: 50px;
  margin-left: 10px;
  font-size: 20px;
  color: #1a1a1a;
  font-weight: bold;
}
.comment-key:focus {
  color: #007dff;
}
.comment-text {
  width: 386px;
  height: 50px;
  text-align: left;
  line-height: 35px;
  font-size: 20px;
  color: #000000;
  border-bottom-color: #bcbcbc;
  border-bottom-width: 0.5px;
}
.comment {
  width: 386px;
  height: 50px;
  background-color: lightgrey;
}

// xxx.js
export default {
  data: {
    inputValue: '',
    commentText: false,
  },
  update() {
    this.commentText = !this.commentText;
  },
  updateValue(e) {
    this.inputValue = e.text;
  },
}
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號