vue中slot和template用法传值

1 父页面调用assets-trend子组件,并接受assets-trend子组件传来的参数

<assets-trend style="flex: 2.7">
              <template slot-scope="slot">
                {{slot.slotMsg}}
               
              </template>
            </assets-trend>

2 子页面assets-trend使用slot传值

 <div>
    <template slot="title-tool">
      <slot slotMsg="这是子页面的信息"></slot>
    </template>
</div>

使用方法2-1

父页面填写在子页面显示的内容,标识为asdf,调用子组件el-search

<el-search>
 <template slot="asdf">
     <el-form-item>
       <el-input placeholder="子页面显示的内容"/>
     </el-form-item>
  </template>
</el-search>

子组件中渲染父页面内容的方式

<template v-if="">
  <slot name="asdf"></slot>
</<template>

使用方法2

父页面调用子页面el-search,子页面渲染出父页面的内容
其中needShowParentContent父页面和子页面要一致

<el-search :col-span="8" labelPosition="right" is-fold :form="queryParams" :searchJson="searchJson" @search="handleQuery" @reset="resetQuery">
<template slot="needShowParentContent">
              <el-date-picker
                type="year"
                v-model="queryParams.bonusYear"
                format="yyyy"
                size="mini"
                value-format="yyyy"
                :style="{ width: '100px' }"
                placeholder="请选择"
                clearable>
              </el-date-picker>
或者
 <template v-slot:ssss="needShowParentContent">
            <el-date-picker
              type="year"
              v-model="queryParams.bonusYear"
              format="yyyy"
              size="mini"
              value-format="yyyy"
              :style="{ width: '100px' }"
              placeholder="请选择"
              clearable>
            </el-date-picker>
          </template>
        </el-search>

父页面定义展示的变量的参数

      searchJson: [
        {
          name: 'workDetail',
          label: '工作事项',
          type: 'text'
        },
        {
          name: 'ssss',
          label: '测试',
          type: 'slot'
        }
      ],

子页面接受

循环父页面的searchJson
。。。。。
    <template>
        <slot :name="field.name" :needShowParentContent="field"></slot>
   </template>
。。。。

效果
在这里插入图片描述

使用方法3

父页面使用child组件

    <child>
        <template v-slot:proposalName="slotData">
          <el-button size="mini" type="text" @click="viewMotion(slotData.slotData)">{{slotData.slotData.motionName}}</el-button>
        </template>
      </child>

子页面展示父页面的dom数据,但是值用的子页面的值

<el-table>
 <el-table-column label="名称" prop="motionName">
            <template slot-scope="scope">
              <slot name="proposalName" :slotData="scope.row"></slot>
            </template>
          </el-table-column>
</el-table>
  • 8
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值