上手作一個華爲鴻蒙手錶應用 2 - 在主頁添加一個按鈕並響應點擊事件

接上一篇:https://developer.huawei.com/consumer/cn/forum/topicview?tid=0202356376262560775&fid=0101303901040230869
源碼倉庫地址:https://gitee.com/zhaoquan/harmonyoswatchdemocss

在主頁添加一個按鈕並響應點擊事件

<!-- index.hml -->
<div class="container">
    <text class="title">
        Hello {{title}}
    </text>
    <input type="button" class="btn" value="點我" onclick="clickAction"></input>
</div>

在 index.hml 建立頁面時生成的默認代碼中添加: <input type="button" class="btn" value="點我" onclick="clickAction"></input> java


/*index.css*/
.container {
    flex-direction: column;
/*    display: flex;*/
    justify-content: center;
    align-items: center;
    left: 0px;
    top: 0px;
    width: 454px;
    height: 454px;
}
.title {
    font-size: 30px;
    text-align: center;
    width: 200px;
    height: 100px;
}
.btn{
    width:200px;
    height:50px;
}

在 index.css 建立頁面時生成的默認代碼中修改 container 的樣式: git

  • 再也不用彈性佈局 display: flex,將 display: flex; 註釋並改成 flex-direction: column; 以便豎向排列 container 裏的全部組件;windows

  • 添加 btn 的樣式: .btn{width:200px;height:50px;}

//index.js
export default {
    data: {
        title: 'World'
    },
    clickAction(){
        console.log("我被點擊了")
    }
}

啓動 debug

第一次啓動 debug 好像要下載什麼,我這裏是彈出一個報錯什麼的,我當時沒截圖,點了右下角的一個按鈕,而後windows一個安全提醒,要聯網什麼的,贊成,過一會再點debug就啓動了 Simulator(模擬器,跟預覽器不是一個東西)。安全

以後每次啓動都會有下圖的彈框,點 OK 便可(下面兩個圖說明了兩個位置可啓動 Debug 'entry')。ide

在這裏插入圖片描述
在這裏插入圖片描述

啓動遠程虛擬設備

預覽器,模擬器,遠程虛擬設備佈局

  • 預覽器入口:View -> Tool Windows -> Previewer(要進入到具體頁面編輯代碼,再打開菜單才顯示 Previewer)
  • 模擬器:入口1:Run -> Debug 'entry',入口2:View -> Tool Windows -> simulator(須要入口1執行成功一次纔有)
  • 遠程虛擬設備:Tools ->HVD Manager(留意使用時長限制)

在這裏插入圖片描述
在這裏插入圖片描述

下一篇的連接:
上手作一個華爲鴻蒙手錶應用 3 - 添加訓練頁面並實現其與主頁面的互相跳轉:https://developer.huawei.com/consumer/cn/forum/topicview?tid=0202356576775850798&fid=0101303901040230869flex


原文連接:https://developer.huawei.com/consumer/cn/forum/topicview?tid=0202356408634880779&fid=0101303901040230869
做者:chatterzhaodebug

相關文章
相關標籤/搜索