<div id="app">
            <!---父组件和子组建同时拥有mounted,需要等待子组件挂载完成之后再触发父组件的挂载--->
            <child ref="child"></child>
        </div>
        <template id="child">
            <div>
                <li v-for ="a in arr">{{a}}</li>
            </div>
        </template>

    <script>
        let vm = new Vue({
            el:'#app',
            mounted(){
               this.$nextTick(()=>{//想操作dom就加一个nextTick
                   console.log(this.$refs.child.$el.innerHTML)
               })
    
            },
            components:{
                child:{
                    template:'#child',
                    data(){
                        return { arr:[1,2,3]}
                    },
                    mounted() {
                        this.arr = [4,5,6]//异步操作dom
                    }
                }
            }
        })
    </script>
Last modification:March 21st, 2020 at 05:58 pm
如果觉得我的文章对你有用,请随意赞赏