当前位置: 首页 > article >正文

【Tip】父子组件传值和页面跳转传值方法(vue和uniapp)

          本文介绍了在Vue和uniapp中子组件和父组件之间的传值方法、页面跳转传值方法。

一、父子组件传值

以列表为例:

1、子组件

sonTemplate.vue

(1)挂载显示内容

<el-table>

//列表内容

<el-table>

(2)关键方法

Creat()方法: 子组件列表getList()

Props:绑定要传递的值(父组件传给子组件==用于显示或在子组件上一次操作值基础上操作)

Props:{

sonValue: {
  type: Number|String,
},

}

Submit():$emit(“方法名method1”, values) 传递在子组件操作的值 (子组件传给父组件==值传递)

2、父组件

(1) 挂载内容

<son-template :sonValue=”selectValue” @method1=”getSelectValue”>

(2)关键方法

Import sonTemplate.vue

Compoent:{SonTemplate}

Data(){

selectValue: null,

}

Methods:{

getSelectValue(val){

this.selectValue = val

// 可对val做其他处理filter、map等}

}

二、路由自定义页面跳转和传值(在Vue中)

1、页面跳转

this.$store.dispatch('tagsView/delView', this.$route)

this.$router.push({
  path: '/factory/factoryCheckPlanManager/add',   //'/factory/factoryCheckPlanManager/add为跳转文件的vue目录
  query: {checkPlanId: id, queryParams: this.queryParams}
})

2、接收

create(){

let queryParams = this.$route.query.queryParams

}

三、路由自定义页面跳转和传值(在uniapp中)

1、页面跳转之===父子组件传值(子组件传递给父组件)

页面之间子页面(下一页面)可用$emit返回给父级页面(上一页面),父级页面在onShow方法中监听事件,实现页面之间的组件传值。

常用于较大数据的传送,不宜放在请求地址里

(1) 子页面传值

uni.$emit('updateCheckItem', {
  type:'updateCheckItem',
  checkItem: this.checkItem,
  locationId:Number(this.checkItem.checkUnitLocation)
});

//返回上级页面

uni.navigateBack({
  delta: 1
})

(2) 父页面(上一页面)接收

onShow(){

uni.$off('updateCheckItem');
uni.$once('updateCheckItem', data => {
  if(data.type === "updateCheckItem") {
    that.checkList.forEach((check,key)=>{
      if(check.pointUnitId===data.locationId){
        check.checkItemList.forEach((item,index)=>{
          if(item.id===data.checkItem.id){
            that.checkList[key].checkItemList[index]=data.checkItem;
          }
        })
      }
    })
    uni.hideLoading();
  } else {
    console.log('失败')
  }
})

}

2、页面跳转之===地址跳转

父页面跳转到子页面,要传递的参数值附带在请求地址上,子页面在onLoad函数中接收

(1) 父页面跳转传值

let url="sonVue?describe="+this.checkItem.abnormalDescribe+'&locationId='+this.checkItem.checkUnitLocation;
this.$tab.navigateTo(url);

(2) 子页面接收

sonVue.vue

onLoad(option){
  if(option.describe!=null && option.describe!='null'){
    this.describe=option.describe;
  }


http://www.kler.cn/a/297589.html

相关文章:

  • 批量复制指定文件夹——EXCEL VBA 实现
  • 详解TCP的三次握手
  • okhttp 拦截器用过那些? 什么情况下用的?如何使用?
  • ASP.NET Core 入门教学二十一 分布式追踪技术
  • 全国机器人大赛 Robocon 常州工学院团队首战国三
  • AI实时游戏引擎:颠覆传统游戏开发的新思路
  • 代理IP中的API接口:解锁高效与自动化的网络访问新方式
  • SpringMVC基于注解使用
  • c++ 2024/9/4
  • 大数据与人工智能:脑科学与人工神经网络ANN
  • 加密技术在保护数据安全中的重要作用
  • matlab 基于选权迭代法的空间平面拟合
  • 西门子S7协议(PROFINET端口)转罗克韦尔AB的Ethernet/IP网络通讯
  • 使用批处理脚本自动化启动Unreal Engine项目
  • 2025秋招NLP算法面试真题(十八)-大模型训练数据格式常见问题
  • 【最新教程】网管家电脑监控软件有什么功能?如何安装部署?一文全了解
  • (七十二)第 10 章 内部排序(基数排序)
  • 【Linux】常用的命令
  • vue3 +百度地图 实现 地点检索,输入联想,经纬度,逆地理编码,创建标记,label等
  • Linux IO模型:IO多路复用