VueJS access child component's data from parent

前端 未结 5 1378
心在旅途
心在旅途 2020-11-28 05:10

I\'m using the vue-cli scaffold for webpack

My Vue component structure/heirarchy currently looks like the following:

  • App
    • PDF Template
        <
5条回答
  •  春和景丽
    2020-11-28 05:16

    I am not sure this is a good practice or not.

    In my child component, there are no buttons to emit changed data. its a form with somewhat 5~10 inputs. the data will be submitted once you click the process button in another component. so, I can't emit every property when it's changing.

    So, what I did,

    In my parent component, I can access child's data from "ref"

    e.g

    
    
    
    // js
    methods:{
        process: function(){
            // items is defined object inside data()
            var markdowns = this.$refs.markdowndetails.items 
        }
    }
    

    Note: If you do this all over the application i suggest move to vuex instead.

提交回复
热议问题