头图

Hello_kugou.vue

<template>
  <div>
    <!--组件是可以复用 -->
    <Hello_kugou :message="msg" static='56' :list="list" ref="hellokugou"></Hello_kugou>
    <!--父子组件访问方式 ,父组件访问子组件 $refs $children-数组类型(vue2)-->
    <!-- 子组件访问父组件 $parent-->
    <!-- 子组件访问跟组件 $root-->
    <p ref="p"></p>




  </div>
</template>

<script>
import Hello_kugou from "./Hello_kugou.vue";
export default {
  data(){//让每一个组件对象都返回一个对象,不对数据污染
    return{
      msg: 'hellokugoumsg',
      list: [1,2,3]
    };
  },
  components:{
    Hello_kugou
  },
  methods:{
    // 在子组件理  $emit 触发事件
    sendParent:function (){
      //this.$emit('事件名称', '发送的事件参数')
      this.$emit('injectMsg', this.msg)
    }
  },
  mounted() {
    console.log(this.$refs);
  },
  name: "Content"
}
</script>

<style scoped>

</style>

image.png


锅包肉
97 声望17 粉丝

这个人很懒,没有什么说的。