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 ...
随机推荐
- oracle_多表查询02
多表查询 select * from BONUS; select * from DEPT; select * from EMP; select * from SALGRADE; BONUS表 ENAM ...
- SIP中From ,Contact, Via 和 Record-Route/Route
转载:http://eadgar.blogbus.com/logs/374635.html 注意:以下内容适用于SIP消息中,在具体的应用环境中,例如IMS,每个消息头都有其他独特的意义,但不会和以下 ...
- bootstrap-selectpicker 插件事件
$('#id').on('show.bs.select', function (e) { //绑定下拉显示列表触发事件 }); $('#id').on('hidden.bs.select', func ...
- nuxt项目打包上线之二
之前写过一篇nuxt打包上线的文章,请看这里:https://www.cnblogs.com/daisygogogo/p/11218809.html 上一篇文章的部署流程有点不好的地方,就是它适用于只 ...
- Oracle 如何查看当前的实例及切换实例
一.Oracle查看当前实例 1.打开终端,输入命令sqlpuls / as sysdba连接到数据库 2.输入命令show parameter name便可以查看当前登录数据库的参数配置,如下可以看 ...
- 销售订单(SO)-API-更新销售订单
更新销售订单和创建销售订单差不多,调用的API相同,只是传入的时候标识不一样:operation := oe_globals.g_opr_update 示例代码如下: PROCEDURE update ...
- python之atexit模块的使用
python atexit 模块定义了一个 register 函数,用于在 python 解释器中注册一个退出函数,这个函数在解释器正常终止时自动执行,一般用来做一些资源清理的操作. atexit 按 ...
- bash shell脚本之获取时间日期
shell中的时间日期获取 cat test5: #!/bin/bash # using the backtick character testing=`date` echo "The da ...
- Java攻城狮面试题录:笔试篇(1)
1.作用域public,private,protected,以及不写时的区别答:区别如下:不写时默认为friendly 2.ArrayList和Vector的区别,HashMap和Hashtable的 ...
- Delphi 类类型