VUE 父子组件之间通信传值 props和 $emit

1、父组件传值给子组件props

父组件得到的值translateText
 data(){
    return{
      translateText:''  
    }
  },
 //props接收父组件传过来的translateText值
  props:[
      "translateText"
  ]

2、子组件传值给父组件 $emit

  data(){
      return{
          inputValue:'',
          lang:''
      }
  },
 methods:{
      formsubmit:function(e){
    //   alert(this.inputValue);
          this.$emit('formSubmit',this.inputValue,this.lang) //this.$emit()事件注册方法,传递一个事件formSubmit和参数this.inputVlue到根组件APP.vue
        // this.$http.get('https://translate.yandex.net/api/v1.5/tr/translate?key=trnsl.1.1.20180726T032631Z.8496e1f4734b42fa.4c4e2d1b85ec5607963552f855d8ce1238676aa7&lang=en&text='+this.inputValue)
        // .then((response)=>{
        //     console.log(response.body);
        //     this.translateText=response.body
        // })
        e.preventDefault() //阻止事件冒泡,防止刷新页面
      }
  }

$smit可以传递参数也可以传递事件

 

转载于:https://www.cnblogs.com/xxflz/p/10231445.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值