码迷,mamicode.com
首页 > 其他好文 > 详细

vue子组件向父组件传递数据

时间:2017-08-12 12:42:25      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:asc   limit   mod   get   vue   --   blog   exp   传递数据   

子组件
<template>
    <div id="header">
      <input type="text" v-model="username" @change="setUser">
    </div>


</template>

<script type="text/ecmascript-6">
    export default{
        props: {
        },
        data()
        {
            return {
                username:‘‘
            }
        },
        created() {

        },
        methods: {
            setUser:function () {
              this.$emit(transferUser,this.username);
            }
        },
        components: {},
        computed: {}
    }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="stylus" rel="stylesheet/stylus">

</style>
父组件
<template>
  <div id="app">
    <v-header @transferUser="getUser"></v-header>
    <div>用户名{{user}}</div>
  </div>

</template>

<script type="text/ecmascript-6">
  import header from components/header/header.vue;

  export default{
        props: {},
        data()
        {
            return {
              user:‘‘
            }
        },
        created() {

        },
        methods: {
            getUser(msg){
                this.user=msg;
            }

        },
        components: {
            v-header:header,
        },
        computed: {}
    }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="stylus" rel="stylesheet/stylus">

</style>

 

vue子组件向父组件传递数据

标签:asc   limit   mod   get   vue   --   blog   exp   传递数据   

原文地址:http://www.cnblogs.com/norm/p/7349762.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!