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 ...
随机推荐
- MQTT协议探究(一)
1 准备阶段 MQTT客户端:https://www.cnblogs.com/linzhanfly/p/9923577.html WireShark MQTT服务器(iot.eclipse.org) ...
- JS 实现继承的方法 ES6 and ES5
继承 ES6 方法 (类的继承) ES6中有一个属性的 extends 语法: • class Father {} • class Son extends Father{} 注意:是子类 ...
- mycat sql timeout 问题解决
发现程序中有个批量update语句需要update 16000多条数据导致超时 2019-11-06 10:35:28.312 pool-9-thread-24 ERROR com.hp.nova.c ...
- C++ STL 之 deque容器 打分案例(内含sort排序用法)
#include <iostream> #include <vector> #include <time.h> #include <deque> #in ...
- python小知识- webbrowser模块 + join()方法
一.join描述 将序列中的元素以指定的字符连接生成一个新的字符串. 语法 语法: ‘sep’.join(seq) 参数说明: sep:分隔符.可以为空 seq:要连接的元素序列.字符串.元组.字典 ...
- 3.MySQL的架构介绍
MySQL简介: 高级MySQL:mysql 内核 sql优化工程师 mysql服务器的优化 各种参数常量设定 查询语句优化 主从复制 软硬件升级 容灾备份 sql编程 完整的mysql优化需要很深的 ...
- List集合复制
方法一: public static void main(String[] args) { // TODO Auto-generated method stub List<String> ...
- C# PDF 填值 填充数据
看效果图 /// <summary> /// 赛事结果PDF /// </summary> /// <param name="model"> ...
- 网络编程实现简单的ssh
客户端:客户端实例 ---> 建立连接 ----> 发送内容 ---> 接受内容. import socket client = socket.socket() client.c ...
- easyUI 布局
Layout(布局) 布局容器有5个区域:北.南.东.西和中间.中间区域面板是必须的,边缘的面板都是可选的. 每个边缘区域面板都可以通过拖拽其边框改变大小,也可以点击折叠按钮将面板折叠起来.布局可以进 ...