自定义事件,子传父
子
<template>
<div>
<button @click="toParent">点击传到父级</button>
</div>
</template>
<script>
export default {
name: 'child',
methods: {
toParent () {
this.$emit('fromChild', 'child')
}
}
}
</script>
<template>
<div>
<p>子级传过来的值:{{childVal}}</p>
<child @fromChild="getChild"></child>
</div>
</template>
<script>
import child from "@/components/child";
export default {
name: 'parent',
data () {
return {
childVal: ''
}
},
components: {
child
},
methods: {
getChild (v) {
this.childVal = v;
}
}
}
</script>
转载请注明原文地址:https://blackberry.8miu.com/read-33361.html