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子组件通知父组件使用方法的更多相关文章

  1. vue 子组件调用父组件的方法

    vue中 父子组件的通信: 子组件通过 props: { //子组件中写的. childMsg: { //字段名 type: Array,//类型 default: [0,0,0] //这样可以指定默 ...

  2. Vue子组件调用父组件的方法

    Vue子组件调用父组件的方法   Vue中子组件调用父组件的方法,这里有三种方法提供参考 第一种方法是直接在子组件中通过this.$parent.event来调用父组件的方法 父组件 <temp ...

  3. 关于Vue中,父组件获取子组件的数据(子组件调用父组件函数)的方法

    1. 父组件调用子组件时,在调用处传给子组件一个方法 :on-update="updateData"   2. 子组件在props中,接收这个方法并声明 props: { onUp ...

  4. Vue父组件向子组件传递方法(自定义方法)并且子组件向父组件传递数据

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. vue父组件调用子组件方法、父组件向子组件传值、子组件向父组件传值

      一.父组件调用子组件方法 父组件代码  parent.vue <template> <div> <button @click="parentFun" ...

  6. vue 父组件使用keep-alive和infinite-scroll导致在子组件触发父组件的infinite-scroll方法

    (vue.js)vue 父组件使用keep-alive和infinite-scroll导致在子组件触发父组件的infinite-scroll方法”问题疑问,本网通过在网上对“ (vue.js)vue ...

  7. vue中子组件调用父组件里面的数据和方法 父组件调用子组件的数据和方法

    1.子组件直接调用父组件的数据和方法 在父组件father,vue <template> <div> <!-- 父组件里面的数据 --> <p>父组件里 ...

  8. VUE 子组件向父组件传值 , 并且触发父组件方法(函数)

    目标:封装一个  搜索组件 <子组件需要传一个或者多个搜索参数到父组件,然后父组件执行列表查询函数> 1.子组件 <div> <input v-model="l ...

  9. 2.Vue子组件给父组件通信

    子组件给父组件通信 如果子组件想要改变数据呢?这在vue中是不允许的,因为vue只允许单向数据传递,这时候我们可以通过触发事件来通知父组件改变数据,从而达到改变子组件数据的目的 子组件: <te ...

随机推荐

  1. oracle基本查询01

    /*数据库-----> 数据库实例----->表空间[逻辑单位]------>数据文件[物理单位] 通常情况下oracle数据库只会有一个实例ORCL 新建一个项目: MYSQL:创 ...

  2. hdu 1068 最大子序列和变形,,,

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #d ...

  3. iview表单验证数字

    验证输入字符串必须为数字 html: <FormItem label="兑换积分:" prop="exchangeIntegral"> <In ...

  4. chartjs显示数值标签插件:chartjs-plugin-datalabels

    Getting Started #Installation #npm   npm install chartjs-plugin-datalabels --save This plugin can al ...

  5. c++11 原生字符串字面值

    c++11 原生字符串字面值 #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> #in ...

  6. Category与Extension详解

    自己做笔录 用来后来回顾.. (一) Category 1.什么是category category是objective-C 2.0之后添加的语言特性,别人口中的分类.类别其实都是指category. ...

  7. ubuntu安装交叉编译器

    # sudo apt-get install gcc-arm-linux-gnueabi # sudo apt-get install g++-arm-linux-gnueabi 官方下载 https ...

  8. 电脑设置自动关机和取消自动关机代码bat命令

    一.设置定时关机bat 1.首先在桌面新建一个记事本txt 2.打开记事本,输入“shutdown -s -t 1260 ”1260是指1260秒,即21分钟内关机.可以修改成别的时间. 3.保存后, ...

  9. P4151 最大XOR和路径 线性基

    题解见:https://www.luogu.org/problemnew/solution/P4151 其实就是找出所有环 把环上所有边异或起来得到的值扔到线性基里面 然后随便走一条从1~n的链 最后 ...

  10. 利用Struts上传文件

    在利用struts2完成上传文件到服务器时,遇到获取不到文件名 原因是在Action中的属性名没有和jsp中的属性名匹配 <%@ page language="java" i ...