vue 父子组件通讯--props,refs(muse-ui,vue.js2.0)

dataset的使用(结合vue使用碰到了坑) 在HTML5中我们可以使用data-前缀设置我们需要的自定义属性,来进行一些数据的存放。 <div data-id="test">test</div> 这里的data-前缀就被称为data属性;我们可以通过dataset来获取data属性。下面是两个例子: 例1: <body> <div id="div1" data-index="0" data-a="牛啊牛啊">test1</div> <div id="div2" . 阅读详情

<template>
  <div class="app-main">
    <app-head msg="客户名称/手机号码" v-on:getSearchContent="searchTop"></app-head>

    <!--子组件--客户新建的弹出框-->
    <client-pop-add ref="clientPopAdd"></client-pop-add>

    <!--子组件--客户修改的弹出框-->
    <client-pop-update ref="clientPopUpdate" title='编辑客户' :name="updateName" :tel="updateTel" :addr="updateAddr"
                       :id="updateId" :index="updateIndex" :money="updateMoney" v-on:getUpdateData="updateListData"></client-pop-update>


    <mu-appbar :zDepth='0' class="app-select">
      <!-- 放下拉框 -->
      <select slot="left" class="select">
        <option value="0">全部客户</option>
        <option value="1">欠款客户</option>
      </select>

      <button class='add-button'@click="showPop">
      <i class="icon icon-加号"></i>
    </button>

    </mu-appbar>
    <div class="tabcontent client-wrapper" id='table'>

      <!--下拉刷新-->
      <!--<mu-refresh-control :refreshing="refreshing" :trigger="trigger" @refresh="refresh"/>-->

      <!-- 下边列表部分 -->
      <mu-table :fixedFooter="fixedFooter" :fixedHeader="fixedHeader" :height="height"
                :enableSelectAll="enableSelectAll" :multiSelectable="multiSelectable"
                :selectable="selectable" :showCheckbox="showCheckbox" class='table-self' id='tbody'>
        <mu-thead slot="header" class="app-thead">
          <mu-tr>
            <mu-th tooltip="序号">序号</mu-th>
            <mu-th tooltip="客户名称">客户名称</mu-th>
            <mu-th tooltip="手机号码">手机号码</mu-th>
            <mu-th tooltip="余额">余额</mu-th>
            <mu-th tooltip="收货信息">收货信息</mu-th>
            <mu-th tooltip="修改"></mu-th>
          </mu-tr>
        </mu-thead>

        <mu-tbody class="app-tbody">
          <mu-tr v-for="item,index in list" :key="index">
            <mu-td>{{index + 1}}</mu-td>
            <mu-td>{{item.client_name}}</mu-td>
            <mu-td>{{item.tel}}</mu-td>
            <mu-td>{{item.money}}</mu-td>
            <mu-td>{{item.addr+'id::'+item.id+'index::'+index}}</mu-td>
            <mu-td>
              <i data-v-d00743b8="" class="icon icon-编辑红" :id=item.id @click=showUpdate(item,index)></i>
          </mu-td>
          </mu-tr>
        </mu-tbody>

        <!--加载更多-->
        <mu-infinite-scroll :scroller="scroller" :loading="loading" :loadingText='loadingText'
        @load="loadMore" v-show=loading id='load-icon'/>
      </mu-table>
    </div>
  </div>
</template>
<script>
import header from '@/components/header/header'

import clientPop from '@/components/client/client-pop'


export default {
  data () {
    const list = []
    for (let i = 0; i < 20; i++) {
      const item = {};
      item.id = i;
      item.client_name = 'name' + (i + 1);
      item.tel = (i + 1);
      item.money = (i + 1);
      item.addr = i;
      list.push(item);
    }
    return {
      fixedHeader: true,
      fixedFooter: true,
      selectable: false,
      multiSelectable: false,
      enableSelectAll: false,
      showCheckbox: false,
      height: 'calc(100% - 42px)',
      //refreshing: false,
      //trigger: null,
      loading: false,
      scroller: null,
      loadingText: '努力加载中...',
      list,
      num: 15,
      updateName:'',
      updateTel:'',
      updateAddr:'',
      updateId:'',
      updateIndex:'',
      updateMoney:''
    }
  },
  components: {
    appHead: header,
    clientPopAdd:clientPop,
    clientPopUpdate:clientPop
  },
  mounted () {
    //this.trigger = document.getElementById('table');

    //this.scroller = document.getElementById('tbody');
    //this.scroller=document.getElementsByClassName('app-tbody')[0];
    var a = document.getElementById("tbody").getElementsByTagName("div");
    //console.log(a);
    this.scroller = a[19];

    //console.log(this.scroller);

    document.getElementById('load-icon').style.width = document.body.clientWidth - 20 + 'px';//减20--滚动条影响会出现横向滚动条如果不减
    console.log(document.body.clientWidth);
  },
  methods: {
    //refresh () {
    //this.refreshing = true
    //console.log('refreshed!!!');
    //setTimeout(() => {
    // this.refreshing = false
    //}, 1000)
    //},
    loadMore () {
      console.log('loading more!!!');
      this.loading = true
      setTimeout(() => {
        for (let i = this.num; i < this.num + 5; i++) {
        const item={};
        item.id=i;
        item.client_name='name'+(i+1);
        item.tel=(i+1);
        item.money=(i+1);
        item.addr=i;
        this.list.push(item);
      }
      this.num += 5

      this.loading = false
    }, 2000)
    },
    showPop (){//点击新增,弹出客户新建框
      this.$refs.clientPopAdd.toggle(true);
    },
    showUpdate(item,index){//弹出修改
      this.$refs.clientPopUpdate.toggle(true);
      this.updateName=item.client_name;
      this.updateTel=item.tel;
      this.updateAddr=item.addr;
      this.updateId=item.id;
      this.updateIndex=index;
      this.updateMoney=item.money;
    },
    searchTop(res){
      console.log('top-search-text::'+res);
    },
    updateListData(){
      console.log(arguments);
      //      this.list[0].addr='feofe';
      //      this.set(this.list, 0, 'feofe');
      var obj_temp={};
      obj_temp.id=arguments[4];
      obj_temp.client_name=arguments[0];
      obj_temp.tel=arguments[1];
      obj_temp.money=arguments[3];
      obj_temp.addr=arguments[2];
      this.list.splice(arguments[5], 1,obj_temp);
    }
  }
}
</script>
<style scoped>
.mu-td, .mu-th {
  text-align: center;
}

.app-thead {
  background: rgb(240, 240, 240);
  border: 0;
}

.app-thead .mu-th,
.app-thead .mu-tr {
  height: 40px;
}

.app-tbody .mu-tr {
  border-bottom: 1px solid #FDDBE1;
}

.app-main .tabcontent {
  height: calc(100% - 50px - 64px);
}

.table-self {
  height: 100%;
}

.app-tbody {
  overflow-y: scroll;
}

.mu-table {
  overflow-x: hidden;
}

.app-select{
  position: relative;
}
.add-button {
  width: 50px;
  height: 50px;
  line-height: 54px;
  position: absolute;
  top: 0;
  right: 0;
  background-color: #F8637D;
  border: 0;
  color: white;
  /*font-size: 40px;*/
  /*font-weight: 100;*/
}

</style>
以上为父组件:


如下是子组件:

<template>
  <div class="pop-container">
    <mu-drawer right :open="open" :docked="docked" @close="toggle()" :width='350' @show="test()">
    <div class="line-li mr25">
      <i data-v-d00743b8="" class="icon icon-客户红40"></i>
      <span class="title red">{{title}}</span>
    </div>

    <div class="line-li mr25">
      <label><span class="red needed">*</span>客户名称:</label>
      <input type="text" v-bind:value="name" ref="input1" @input="input1"/>
    </div>
    <div class="line-li">
      <label><span class="red needed">*</span>手机号码:</label>
      <input type="number" v-bind:value="tel" ref="input2" @input="input2"/>
    </div>
    <div class="line-li">
      <label class="tx-label"><span class="red needed notneed">*</span>收货信息:</label>
      <textarea v-bind:value="addr" ref="input3" @input="input3"></textarea>
    </div>

    <div class="bottom">
      <button class="bg-red" v-bind:value="id" ref="button" v-bind:data-index="index" v-bind:data-money="money" @click='postUpdateData'>保存</button>
      <button class="bg-gray" @click="toggle()">取消</button>
    </div>
    </mu-drawer>
  </div>
  </template>

<script>
export default {
  name:'popClient',
  props: {
    title: {
      type: String,
      default: "新建客户"
    },
    name:{
      type:String,
      default:''
    },
    tel:{
      type: [String,Number],
      default: ''
    },
    addr:{
      type:[String,Number],
      default:''
    },
    id:{
      type:[String,Number],
      default:''
    },
    index:{
      type:[String,Number],
      default:''
    },
    money:{
      type:[String,Number],
      default:''
    }
  },
  data () {
    return {
      open: false,
      docked: true,
      pinput1:'',
      pinput2:'',
      pinput3:''
    }
  },
  methods: {
    toggle (flag) {
      this.open = !this.open
      this.docked = !flag
    },
    test(){
        this.pinput1=this.$refs.input1.value;
        this.pinput2=this.$refs.input2.value;
        this.pinput3=this.$refs.input3.value;
        console.log(this.pinput1+this.pinput2+this.pinput3);
    },
    postUpdateData(){
//      console.log(this.pinput1+this.pinput2+this.pinput3);
//      var item_index=this.$refs.button;
      var index=this.$refs.button.dataset.index;
      var id=this.$refs.button.value;
      var money=this.$refs.button.dataset.money;
      this.$emit("getUpdateData", this.pinput1,this.pinput2,this.pinput3,money,id,index);
      this.toggle();
    },
    input1(){
      this.pinput1=this.$refs.input1.value;
    },
    input2(){
      this.pinput2=this.$refs.input2.value;
    },
    input3(){
      this.pinput3=this.$refs.input3.value;
    }
  }
}
</script>
<style scoped>
.pop-container{
  position: relative;
}

.line-li{
  margin-top:35px;
  margin-left:25px;
  position: relative;
}
.mr25{
  margin-top:25px;
}
.icon-客户红40{
  font-size: 40px;
}
.red{
  color:#ff0000;
}
.title{
  display: inline-block;
  height:40px;
  line-height:40px;
  font-size: 16px;
  margin-left: 5px;
}

.needed{
  font-size: 20px;
  vertical-align: bottom;
  padding-right: 4px;
  padding-left: 2px;
}
.notneed{
  opacity: 0;
}
label{
  color:#666666;
  padding-right: 4px;
}
input{
  width: 208px;
  height:40px;
  padding-left: 5px;
}
textarea{
  width:208px;
  padding:5px;
  height:400px;
  resize: none;
}
.tx-label{
  position: relative;
  top:-385px;
}

.bottom{
  position: absolute;
  bottom: 0;
  height: 60px;
  line-height: 60px;
  border:1px solid rgb(236,225,229);
  border-left:0;
  border-right:0;
  width:100%;
  background-color:#FEF5F7;
}
button{
  height:40px;
  width:140px;
  text-align: center;
  line-height: 40px;
  color:white;
  border:0;
  border-radius: 5px;
}
.bg-red{
  background-color: #F8637D;
  margin-left:25px;
}
.bg-gray{
  background-color: rgb(204,204,204);
  position: absolute;
  top:10px;
  right:25px;
}
</style>


主要使用的是:子组件通过props获取父组件传过来的信息,父组件通过emit,on的方法获得子组件传的信息;
目前子组件中获取input的值是通过refs,而非v-model,如何改进有待思考
手把手教你用FPGA驱动DAC8830:一个Verilog SPI驱动模块的完整实现与调试 本文详细介绍了如何使用FPGA通过Verilog实现DAC8830的SPI驱动模块,包括SPI通信机制解析、Verilog模块设计、代码优化及调试技巧。重点解决时钟同步、状态机设计等工程实践问题,适用于音频处理、仪器仪表等高精度数模转换场景。 阅读详情

相关推荐

halcon 深度学习标注_Halcon deep learning之目标检测笔记(一)

设置输入输出的路径输入路径有两个,一个是图像路径HalconImageDir,一个是Json文件路径PillBagJsonFile。这两个参数用于后续在图像路径中读取coco文件。输出路径首先定义一个新的文件夹路径,用于存放样本和模型文件等数据。设置基于深度学习的目标检测模型的路径,该模型文件以.hdl结尾。设置样本数据文件夹ExampleDataDir:'detect_pills_data'数据...

weixin_27885313的博客 2701

【Vue 快速入门系列】ref、props、mixin、插件使用、样式混合解决方案合集

在前面介绍到了Vue的一些基本概念与如何使用Vue,并通过node中的npm 使用vue脚手架(vue-cli)搭建了一个简单的Vue应用,其实所有的Vue项目搭建的时候都是换汤不换药。本篇博客将会介绍几个Vue中常用的配置,refs、props、mixin、插件、样式混合问题等等。

一个非常Cool的人 1207

RFSOC实战解析:MTS多片同步的时序校准与相位相干实现

本文深入解析了在RFSOC平台上实现MTS多片同步的关键技术与实战流程。文章从相位相干的重要性出发,详细阐述了SYSREF与SYNC信号的协同工作机制,并提供了从硬件时钟配置到软件API调用的完整MTS实现步骤。重点探讨了时序校准的核心方法,旨在帮助工程师解决多通道系统相位不一致的难题,确保ADC与DAC达到精确的相位相干,从而构建高性能的MIMO和相控阵系统。

weixin_29206669的博客 194

React三大属性之props与refs简介

之前介绍的state属性主要作用是标记组件的状态,且可以在初始化组件时就设置,而props属性主要是用来接收外部传入的数据。考虑如下诉求:实现人的信息的展示,人的信息由组件外的数据传入。此时需要使用props属性,React能自动收集组件标签中的各个属性数据,放入props属性中,然后在render方法中可以使用props属性中的数据: class MyDemo extends React.Component{ render() { const {name, age, sex}

weixin_46628668的博客 724

MFC使用Websocket通讯介绍和实例(附完整源码)

踩坑点,下载了好几个boost版本编译,经常出问题,后来搜索了好久资料才发现如下评论:WebSocket++0.8.2 has been tested through Boost 1.72。WebSocketpp依赖于boost,因此在使用WebSocketpp前需要编译Boost;所以我们直接下载Boost 1.72的windows版的进行安装,安装完成还需要编译;WebSocketpp也叫WebSocket++;服务编译好之后,使用。

weixin_42530684的博客 1171

凌欧通用FOC框架解析(5.程序环流程)

结构体:电流内环.这是一个结构体函数占空比13.

weixin_43756295的博客 2944

vue父子组件通信props、$refs、$emit及非父子组件vuex的使用

vue父子组件通信方法props、$refs、$emit及非父子组件通信vuex使用方法总结。

m0_46169419的博客 4270

[QMT量化交易小白入门]-八十九、深度学习训练多维特征进行金融价格行情预测

本专栏主要是介绍QMT的基础用法,常见函数,写策略的方法,也会分享一些量化交易的思路,大概会写100篇左右。QMT的相关资料较少,在使用过程中不断的摸索,遇到了一些问题,记录下来和大家一起沟通,共同进步。

木头大左的博客 222

React-组件三大核心属性: state、props、refs

1、state state是组件对象最重要的属性, 值是对象.React 把组件看成是一个状态机(State Machines)。通过与用户的交互,实现不同状态,然后渲染 UI,让用户界面和数据保持一致。React 里,只需更新组件的 state,然后根据新的 state 重新渲染用户界面(不要操作 DOM)。 例子: //1.创建组件 class Weather extends React.Component{ //初始化状态 state = {isHot:false,wind:'微风'

weixin_53412458的博客 1384

DaVinci配置DID之二:工具链配置

本系列主要基于DaVinCi工具链来展开具体DID读写的配置以及最终实现。1,CDD准备2,工具链配置3,代码实现4,验证结果本文讲述流程2话不多说,走你~博主也是AutoSar小白,如果哪里表达的有问题,还请大佬们指点指点哈。接下来,让我们在下章关于代码具体实现的博文再相会哈~

weixin_48498880的博客 5743

【Google Play 上架】内部 / 封闭 / 开放 测试全解 — “只跑一个就能上架”?不行!

Google Play新规要求个人开发者账号在2023年11月13日后必须通过封闭测试(Closed testing)才能上架应用。封闭测试需要至少12名测试者连续14天保持参与状态,而内部测试和开放测试不能替代这一要求。三类测试轨道各有特点:内部测试用于快速内部验证,封闭测试是上架必经环节,开放测试面向更广泛用户但非必需。上架流程建议先内部测试修复问题,再启动封闭测试满足14天要求,最后申请生产发布。组织账号和早期个人账号可能不受此限制。开发者应提前规划测试人群,确保持续测试周期,并关注Play Cons

技术小甜甜:传播可落地技术,帮助个人和企业降低解决真实场景问题的成本 2803

vue 父子组件双向数据绑定,调用 使用ref获取原生DOM

在:自定义属性.sync=“传递过去的变量”自定义属性名后面加上.sync表示传递的是一个同步变量。拿到子组件对象就可以直接调用子组件的methods函数或者修改 自组建的data的数据。子组件: HelloWorld.vue: 点击子组件button更改父组件的数据。如果ref属性是定义在自定义组件标签上面 那么最终获取的就是子组件的对象。父组件: app.vue: 点击button更改子组件msg数据。子组件: Child.vue : 点击更改父组件数据。父组件:this.$children[索引]

lin150080的博客 1035

199、医疗内窥镜影像:微型镜头与高色彩保真度的ISP定制化方案

医疗内窥镜影像系统开发面临三大光学挑战:衍射极限导致分辨率下降,微型镜头色差严重,镀膜不足引发红外漏光。团队通过定制化ISP方案解决问题:采用分区色差补偿、红外泄露补偿技术,开发12区域分段颜色校正矩阵,并设计自适应伽马曲线。关键经验包括锁定白平衡避免术中偏色,优化FPGA流水线确保30fps流畅度,强调光学标定优先于算法优化。最终方案使DeltaE降至3以下,满足医生对组织颜色细微差异的识别需求,尤其解决了血管与脂肪边界辨识难题。

zzfmlxs的博客 265

JavaScript入门 组件/组件通讯:父传子/子传父/refs属性 Day03

组件/组件通讯:父传子/子传父/refs属性

qq_63354840的博客 863

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

组件间传递信息

1 prop 父子组件 <!-- 父组件 --> <template> <div> <my-child :parentMessage="parentMessage"></my-child> </div> </template> <script> import MyChild from '@components/common/MyChild' export def

weixin_42371145的博客 346

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

2026前端面试题!(附答案及解析)(2026.9月最新版)

文章目录1.JSONP原理2. cookie、sessionStorage、localStorage的区别3.link和a标签区别4 vue中的跨域问题5 webpack面试题6 浏览器与服务器的交互原理7 什么是CSS盒模型 >>> -IE盒模型和W3C盒模型8 A解释一下闭包,B为什么要使用闭包?9 解释一下作用域链10 如何处理不让别人盗用你的图片,访问你的服务器资源?11 如何优化网站性能vue路由面试题1.对于MVVM的理解?2 Vue的生命周期1 什么是vue生命

weixin_43617604的博客 8万+

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

13.Vue - ref属性、props配置、mixin混入、插件、scoped样式

1.被用来给元素或子组件注册引用信息(id的替代者)2.应用在html标签上获取的是真实DOM元素,应用在组件标签上是组件实例对象(vc)3.使用方式:打标识: .... 或获取:this.$refs.xxx具体看下图代码。

weixin_51351637的博客 1393

AI问答-Vue实例属性/实例方法:$refs、$emit、$attrs、$props、$data...

在Vue.js中,符号通常用于表示Vue实例或组件上的内置属性和方法,这些被称为“实例属性”或“实例方法”。以下是一些常见的以。

snow的博客 1557

vuejs之父子组件访问【$refs】【$children】

​$refs(reference 缩略)是一个对象,持有当前组件中注册过refattribute的所有 DOM 元素和组件实例。 ​

CamphorBlossom的博客 3163

Vue(六)Vue中父子组件的三种通讯方式(props、$ref、$emit)【上】

组件化开发是 vue.js 最强大的功能之一,而组件实例的作用域是相互独立的,这就意味着不同组件之间的数据无法相互引用。那么组件间如何通信,也就成为了vue中重点知识了。这篇文章将会通过props、$ref和 $emit 这几个知识点,来讲解如何实现父子组件间通信。 一、让我们来康康父子组件是如何使用的 我们先来建两个组件father.vue和child.vue作为示例的基础。 Father.vue(父组件) <template> <div> &...

io_123io_123的博客 2517

【精讲】vue框架 vue组件中的ref、props传值并修改、混合(子组件重复部分利用混合可以减少代码量的重复编写)

【精讲】vue框架 vue组件中的ref、props传值并修改、混合(子组件重复部分利用混合可以减少代码量的重复编写)

m0_59505309的博客 3357

浅谈vue refs和props的区别

常见场景:有一个子组件,父组件需要调用里面的子组件的方法,可以这样操作: <child ref="mychild"></child> 父组件:this.$refs.mychild.子组件方法() =>这样就可以调用子组件的方法 this.$refs.cardForm.scShowFrom = true =>这样就可以修改子组件的属性 那么这种修改子组件属性的方法和props传进去的更改子组件的方法有何不同? ...

weixin_38233449的博客 945

vue 父子传值 ref和props两种方法

关于vue父子传值的ref和props和emit三种方法

weixin_48854245的博客 953

vue的ref属性和props配置项

打标识:.....或备注:props是只读的,Vue底层会检测你对props的修改,如果进行了修改,就会发出警告。2.应用在htm1标签上获取的是真实DOM元素,应用在组件标签上是组件实例对象(vc)required: true //必要性。default: '老王' //默认值。type: String //类型。第三种方式(限制类型、限制必要性,指定默认值)8.4、props配置项。第二种方式(限制类型)

weilaaer的博客 458

Vue ref属性,props配置项,mixin混入,scoped样式,slot插槽

Vue ref属性,props配置项,mixin混入,scoped样式,slot插槽

嘤嘤鸭的博客 522

Vue-数据绑定(通过dataset获取)

将一些数据绑定到元素中方便后续使用 :data-数据名称 = "数据" 直接获得数据 <div :data-index = "1" ref="group"></div> let index = this.$refs.group.dataset.index 触发事件获得 <ul class="list-keys"> <li v-for="(key,index) in keys" :key="index" :d

lihui61357457的博客 2627
上一篇: 分页显示--html,js处理
下一篇: css左右摆动动画
hhhhh--hhhhh
博客等级 码龄11年 2粉丝 14原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值