vue子组件通知父组件使用方法
vue子组件通知父组件使用方法
<template>
<mt-field placeholder="验证码" v-model="getverifycode" :attr="{maxlength: 4}">
<img :src="imgcode" class="verifycode">
<i class="icon iconfont iconefresh" @click="getVcode"></i>
</mt-field>
</template> <script>
import { Toast } from 'mint-ui'
import '../utils/http'
import { createguid } from '../utils/util'
import axios from 'axios'
export default {
data() {
return {
imgcode: ''
}
},
props: ['verifycode'],
mounted: function() {
this.getVcode()
},
computed: {
getverifycode: {
get: function() {
return this.verifycode //将props中的verifycode值赋给getverifycode
},
set: function(val) {
this.$emit('input', val) //通过$emit触发父组件
}
}
},
methods: {
getVcode: function() {
let guid = createguid()
var vm = this
axios
.post('接口url', {
requestId: guid
})
.then(response => {
if (response.data.result.returnCode == '0') {
this.imgcode = 'data:image/png;base64,' + response.data.content
this.$emit('vcodeguid', guid) //通过$emit触发父组件
} else {
Toast('网络不给力,请重试')
}
})
.catch(error => {
console.log(error)
})
}
}
}
</script>
父组件使用方法
<template>
<div>
<mt-header fixed title="页面名称">
<router-link to="-1" slot="left">
<mt-button icon="back"></mt-button>
</router-link>
</mt-header>
<div class="content">
<div class="mail-info-txt">
<p>邮箱:{{email}}</p>
</div>
<div class="mailconfirm_form">
<div class="fill-in-list">
<Verifycode ref="vcode" v-model="verifycode" v-on:vcodeguid="handleVcodeguid"></Verifycode>
</div>
<mt-button type="primary" size="large" :class={active:isActive} @click="resetpsd" :disabled="isBtnDisable"> 发送到该邮箱 </mt-button>
</div>
</div>
</div>
</template> <script>
import { Toast } from 'mint-ui'
import { MessageBox } from 'mint-ui'
import '../utils/http'
import { createguid, getStore, getCookie } from '../utils/util'
import axios from 'axios'
import Verifycode from '@/components/verifycode' //调用子组件 export default {
data() {
return {
email: '', //邮箱
verifycode: '', //验证码
isBtnDisable: true,
isActive: false,
imgcode: '',
requestId:''
}
},
//监听verifycode值变化切换按钮能否点击
watch: {
verifycode: function(val) {
if (val) {
this.isBtnDisable = false
this.isActive = true
} else {
this.isBtnDisable = true
this.isActive = false
}
}
},
created: function() {
let userinfo = JSON.parse(getCookie('userInfo'))
this.email = userinfo ? userinfo.email : ''
},
components: {
Verifycode //声明子组件
},
methods: {
handleVcodeguid: function(guid) { //自定义方法触发事件
this.requestId = guid
},
resetpsd: function() {
let vm = this
axios
.post('接口url', {
Email: this.email,
RequestId: this.requestId,
Code: this.verifycode,
})
.then(response => {
var data = response.data
if (data.result.returnCode == '0') {
MessageBox.alert('已发送至您的邮箱,请注意查收').then(action => {
vm.$router.go(-2)
})
} else {
Toast(data.result.resultMsg)
this.$refs.vcode.getVcode()
}
})
.catch(error => {})
}
}
}
</script>
vue子组件通知父组件使用方法的更多相关文章
- vue 子组件调用父组件的方法
vue中 父子组件的通信: 子组件通过 props: { //子组件中写的. childMsg: { //字段名 type: Array,//类型 default: [0,0,0] //这样可以指定默 ...
- Vue子组件调用父组件的方法
Vue子组件调用父组件的方法 Vue中子组件调用父组件的方法,这里有三种方法提供参考 第一种方法是直接在子组件中通过this.$parent.event来调用父组件的方法 父组件 <temp ...
- 关于Vue中,父组件获取子组件的数据(子组件调用父组件函数)的方法
1. 父组件调用子组件时,在调用处传给子组件一个方法 :on-update="updateData" 2. 子组件在props中,接收这个方法并声明 props: { onUp ...
- Vue父组件向子组件传递方法(自定义方法)并且子组件向父组件传递数据
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- vue父组件调用子组件方法、父组件向子组件传值、子组件向父组件传值
一.父组件调用子组件方法 父组件代码 parent.vue <template> <div> <button @click="parentFun" ...
- vue 父组件使用keep-alive和infinite-scroll导致在子组件触发父组件的infinite-scroll方法
(vue.js)vue 父组件使用keep-alive和infinite-scroll导致在子组件触发父组件的infinite-scroll方法”问题疑问,本网通过在网上对“ (vue.js)vue ...
- vue中子组件调用父组件里面的数据和方法 父组件调用子组件的数据和方法
1.子组件直接调用父组件的数据和方法 在父组件father,vue <template> <div> <!-- 父组件里面的数据 --> <p>父组件里 ...
- VUE 子组件向父组件传值 , 并且触发父组件方法(函数)
目标:封装一个 搜索组件 <子组件需要传一个或者多个搜索参数到父组件,然后父组件执行列表查询函数> 1.子组件 <div> <input v-model="l ...
- 2.Vue子组件给父组件通信
子组件给父组件通信 如果子组件想要改变数据呢?这在vue中是不允许的,因为vue只允许单向数据传递,这时候我们可以通过触发事件来通知父组件改变数据,从而达到改变子组件数据的目的 子组件: <te ...
随机推荐
- linux安装字体库(simSun为例)
在开发过程中,发现报表打印,字体和默认字体不一样.本地开发环境(windows)没问题,但是远程linux一直出现这样的问题.经过排查发现linux没有安装中文字体库宋体. linux查看当前的字体库 ...
- TCP协议探究(四):定时器
1 概述 重传定时器:使用于当希望收到另一端的确认. 坚持(persist)定时器:使窗口大小信息保持不断流动,即使另一端关闭了其接收窗口 保活(keepalive)定时器:用于检测一个空闲连接的另一 ...
- TCP协议探究(一):报文格式与连接建立终止
一 TCP:传输控制协议报文格式 1 TCP服务 提供面向连接.可靠的字节流服务 面向连接意味着两方通信,不支持多播和广播 可靠性的支持: 应用数据被分割成TCP认为最适合发送的数据块.由TCP传递给 ...
- Java门面模式(思维导图)
图1 门面模式[点击查看图片] 1,实体对象类 package com.cnblogs.mufasa.demo1; //3个子系统,解决问题的实体 public class StoreA { //示意 ...
- 使用X.509数字证书加密解密实务(三)-- 使用RSA证书结合对称加密技术加密长数据
一. 使用证书结合对称加密算法加.解密长数据 上一章节讨论了如何使用RSA证书加密数据,文中提到:“Dotnet的RSA实现有个特点,它必须要在明文中添加一些随机数,所以明文不能把128字节占满,实 ...
- sql 行数据找出最大的及所有数据最大的
SELECT @charges=ISNULL(MAX(a.maxcharge), 0.00) FROM( SELECT (SELECT MAX(maxcharge) FROM(VALUES(ilong ...
- Docker 杂记
1.配置阿里云加速 :可以找到各种加速URL.比如 https://tnxkcso1.mirror.aliyuncs.com/ 2.windows 配置: 3.docker info可以看到新的配置已 ...
- service程序改为windows窗体展示
首先将exe程序文件进行快捷创建.然后就会生成一个 exe -shortCut 程序,然后进入属性中,并且进行修改引用路径,在路径xx.exe 后面加一个空格和/tt,保存,这样就可以正常运行了. 如 ...
- Linux I2C核心、总线和设备驱动
目录 更新记录 一.Linux I2C 体系结构 1.1 Linux I2C 体系结构的组成部分 1.2 内核源码文件 1.3 重要的数据结构 二.Linux I2C 核心 2.1 流程 2.2 主要 ...
- SpringBoot--多环境部署配置文件
在resources 下创建 application-{profile}.properties 的配置文件,其中profile是任意名字: test:测试环境 prod:线上环境 pre-prod:预 ...