相关疑难解决方法(0)

vue - 如何传递包装器组件内的插槽?

所以我用模板创建了一个简单的包装器组件:

<wrapper>
   <b-table v-bind="$attrs" v-on="$listeners"></b-table>
</wrapper>
Run Code Online (Sandbox Code Playgroud)

使用$attrs$listeners传递道具和事件.
工作正常,但包装器如何代理<b-table>命名的插槽给孩子?

components wrapper vue.js vue-component

34
推荐指数
4
解决办法
8424
查看次数

将命名槽传递给子组件

由于某些服务器端渲染,我希望能够将命名插槽从父组件传递到子组件,但我不确定正确的机制。我能够让顶级模板通过,但名为 slot of 的子级title似乎无法访问。

<div id="app1">
  <parent>
    <template #forchild>
      <div>
        For child template area
        <template #title>Title!</template>
      </div>
    </template>
  </parent>
</div>

Run Code Online (Sandbox Code Playgroud)
const Child = {
  template: `
    <div class="child">
      Child area
      <slot name="forchild">
        <slot name="title"></slot>
      </slot>
    </div>
  `,
};

const Parent = {
  template: `
    <div class="parent">
      Parent Area
      <child>
        <template #forchild>
          <slot name="forchild"></slot>
        </template>
      </child>
    </div>
  `,
  components: {
    Child,
  },
};

new Vue({
  el: '#app1',
  components: {
    Parent,
  }
});
Run Code Online (Sandbox Code Playgroud)

提琴手

vue.js

7
推荐指数
1
解决办法
111
查看次数

有没有办法将 slot 与 vuetify 数据表组件一起使用?

这是我的组件(我们称之为 BaseTable):

  <v-card>
    <v-card-title>
      {{ title }}
      <v-spacer></v-spacer>
      <v-text-field
        :value="value"
        @input="$emit('input', $event)"
        append-icon="mdi-magnify"
        label="Search"
        single-line
        hide-details
      ></v-text-field>
    </v-card-title>
    <v-data-table
      :search="value"
      :headers="headers"
      :items="items"
      :loading="loading"
      :loading-text="loadingText"
    >
      <slot></slot> <!--Will pass something here -->
    </v-data-table>
  </v-card>
</template>
Run Code Online (Sandbox Code Playgroud)

然后我想通过操作列中的按钮重用 BaseTable:

 <BaseTable
      :headers="headers"
      :items="items"
      :loading="loading"
      loadingText="Getting items... Please wait"
      title="Transfer Request Processing"
      v-model.lazy="search"
    >
      <template v-slot:item.actions="{ item }">
        <v-btn block color="warning" outlined @click="delete(item)">
          <v-icon left class="mr-2">mdi-icon</v-icon>DELETE
        </v-btn>
      </template>
    </BaseTable>
Run Code Online (Sandbox Code Playgroud)

数据以正确的标题显示,但“删除”按钮却没有。我尝试在组件本身上使用模板(效果很好),但我不希望那样。非常感谢您的帮助。

vue.js vue-component vuetify.js

2
推荐指数
1
解决办法
2105
查看次数

标签 统计

vue.js ×3

vue-component ×2

components ×1

vuetify.js ×1

wrapper ×1