标签:tms rip import strong 数据 span str vue def
<template> <div class="app"> <input @click="sendMsg" type="button" value="给父组件传递值"> <!--自定义的事件也可以在template里里面写--> </div> </template> <script> export default { data () { return { //将msg传递给父组件 msg: "我是子组件的msg", } }, methods:{ sendMsg(){ //func: 是父组件指定的传数据绑定的函数,this.msg:子组件给父组件传递的数据 this.$emit(‘func‘,this.msg) } } } <script>
<template>
<div class="app">
<child @func="getMsgFormSon"></child>
</div>
</template>
<script>
import child from ‘./child.vue‘
export default {
data () {
return {
msgFormSon: "this is msg"
}
},
components:{
child,
},
methods:{
getMsgFormSon(data){
this.msgFormSon = data
console.log(this.msgFormSon)
}
}
}
</script>
标签:tms rip import strong 数据 span str vue def
原文地址:https://www.cnblogs.com/Jerry1208/p/11849636.html