美文网首页
两种调用组件方法

两种调用组件方法

作者: 一枚小菜 | 来源:发表于2020-05-18 12:08 被阅读0次

    1.props
    父组件

    <div class="bt1" @click="goaddemployees()">
        <img src="/static/img/usercenter/bt1.png"> 添加
    </div>
    
        <addemployees v-if="show" :show="show" :gbe="gbe"></addemployees>
        import Addemployees from './addemployees'
        components: { Addemployees}
    
    data () {
      return {
        show: false,
            }}
    
      goaddemployees () {
         this.show = true
      },
     gbe () {
         this.show = false
     },
    

    子组件

    <template>
      <div>
        <div class="alls" @click.stop="guanbi()">
          <div class="alls-body" style="position: relative" @click.stop="on()">
          ...
    
    props:{
          gbe:Function
      },
    methods: {
          guanbi () {
            this.gbe()
          },
          on () {
          }
        }
    

    2.$emit
    父组件

    <div class="bt1" @click="goaddperson()">
        <img src="/static/img/usercenter/bt1.png"> 添加
    </div>
    
        <addpeople v-if="show2" :show2="show2" v-on:gbp="gbp"></addpeople>
          import Addpeople from './addpeople'
        components: {Addpeople}
    
    data () {
      return {
        show2: false,
            }}
    
      goaddperson () {
         this.show2 = true
      },
     gbe () {
         this.show2 = false
     },
    

    子组件

    <template>
      <div>
        <div class="alls" @click.stop="guanbi()">
          <div class="alls-body" style="position: relative" @click.stop="on()">
          ...
    
    methods: {
          guanbi () {
              this.$emit('gbp')
          },
          on () {
          }
        }
    

    相关文章

      网友评论

          本文标题:两种调用组件方法

          本文链接:https://www.haomeiwen.com/subject/lmnvohtx.html