子组件怎么读取父组件传过来的数据?(插槽)

父组件:(moreActions是import引入的子组件)

<moreActions slot-scope="scope">  
 <el-button class="operation-button" type="text"  
  @click="showDialog(scope.row)">查看  
  </el-button>  

 <el-button class="operation-button" type="text"  
  @click="showPutStoreDialog(scope.row)">入库  
  </el-button>  

  <el-button class="operation-button" type="text"  
  @click="del(scope.row)">删除  
  </el-button>  
</moreActions>

子组件:怎么去判断父组件传过来几个button按钮?

<template>  
 <div> 
    <slot></slot> 
 </div>  
</template>  

<script>  
  export default {  
        name: "more-actions",  
  data() {  
            return {}  
        }
  }  
</script>  

阅读 3.3k
3 个回答
 <el-button class="operation-button" type="text"  
  @click="showDialog(scope.row)">查看  
  </el-button>  

 <el-button class="operation-button" type="text"  
  @click="showPutStoreDialog(scope.row)">入库  
  </el-button>  

  <el-button class="operation-button" type="text"  
  @click="del(scope.row)">删除  
  </el-button>  

因为你子组件里没别的内容 就一个 <slot>

this.$el.children

dom 都给你了,用选择器获取,或者遍历判断都可以

button数量不应该固定的么,用具名插槽。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题