回复
     HarmonyOS开发-router路由-数据传输
鸿蒙时代
 发布于 2022-3-31 10:19
 浏览
 0收藏
效果展示:
1.建立项目包
2.创建文件

3.代码部分:
4.显示部分:
Index.hml
<div class="container">
    <text class="title">
        <span>记录</span>
    </text>
    <div class="boxs">
        <text class="text"><span>时间:{{ time }}</span></text>
        <text class="text"><span>地点:{{ address }}</span></text>
        <text class="text"><span>人员:{{ personal }}</span></text>
    </div>
    <input type="button" value="上传" onclick="click"></input>
</div>
Index.css
.container {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
}
.title{
    width: 100%;
    text-align: center;
    margin-bottom: 20px;
}
.boxs{
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    width: 100%;
}
.text {
    font-size: 20px;
    color: #333;
    opacity: 0.9;
    margin-bottom: 10px;
    margin-left: 20px;
}
Index.js
import router from '@system.router';
export default {
    data:{
        time: "2022.03.27",
        address:"广东省深圳市*****",
        personal:"*****",
    },
    click(){
        router.push({
            uri:"pages/touter/touter"
        })
    }
}
输入记录部分:
Tuoter.hml
<div class="container">
    <text class="title">
        <span>输入记录</span>
    </text>
    <div class="box">
        <input id="1" type="text" value="{{ time }}" placeholder="输入时间" onchange="getChange"></input>
        <input id="2" type="text" value="{{ address }}" placeholder="输入地点" onchange="getChange"></input>
        <input id="3" type="text" value="{{ personal }}" placeholder="输入人员" onchange="getChange"></input>
        <input type="button" value="提交" onclick="btnClick"></input>
    </div>
</div>
Touter.css
.container {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
}
.title {
    font-size: 30px;
    text-align: center;
    width: 200px;
    height: 100px;
}
.box{
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    height: 200px;
    width: 100%;
}
Touter.js
import router from '@system.router';
export default {
    data:{
        time:"",
        address:"",
        personal:"",
    },
    getChange(e){
        let idName = e.target.id
        if (idName === "1") {
            this.time = e.value
        }else if (idName === "2") {
            this.address = e.value
        }else if (idName === "3") {
            this.personal = e.value
        }
    },
    btnClick(){
        router.push({
            uri:"pages/index/index",
            params:{
                time:this.time,
                address:this.address,
                personal:this.personal,
            }
        })
    }
}
效果展示:


完整代码地址:
https://gitee.com/jltfcloudcn/jump_to/tree/master/router
分类 
 标签 
 HarmonyOS开发-router路由-数据传输.docx 176.13K 17次下载  
        赞
        
 
        收藏 
      
 回复
  相关推荐
 



















