Keep default slot content for named slots?

fnlctrl
创建于
2016-01-28 09:12:31

Consider this:
For a component foo using named slots,

<slot name="a">
    Some Useful Default Content
</slot>
<slot name="b"></slot>

And in another components' template:

<foo>
  <div slot="b"> asdfasdf</div>
</foo>

It gets rendered as:

<div slot="b"> asdfasdf</div>

and <slot name="a"> is discarded!

Wouldn't it be better to let

<slot name="a">
    Some Useful Default Content
</slot>

get rendered even if it's not used in another component's template?

If I intentionally want to suppress slot a, I could just write
<div slot="a"></div> or something like that so that there would be nothing at slot a.
On the other hand, I could really use some default content because I don't want to write them multiple times in different components.

The reason I'm not using unnamed default is that the default slot is rendered anyway,
what I really want is:
If content for slot a is provided, use it, and no default content is shown.
If not, use default.

1条回答
fnlctrl
回复于
2016-01-28 09:25:59
#1

Oops I made a mistake.. there was no issue at all.. really sorry.

当前位于第1页,总计1 条回复

推荐相似问题

v-el behaviour

Hello, right now when we use v-el we are able to register a reference to a DOM element on its owner Vue instance’s $els
讨论数 13
vue
创建时间:2016-01-28 08:34:52

If the component is an asynchronous component, the v-ref is not properly acquired in the parent component

If the component is a async component, then the v-refs is empty. var test = Vue.component('test',{ template:
讨论数 3
vue
创建时间:2016-01-28 08:21:34

how to bind a variable with the dom.scrollTop?

I need handle the scrolling in the document when click event triggered? what do I do? 请问我应该怎样绑定dom的scrollTop到viewModel的属
讨论数 2
vue
创建时间:2016-01-28 07:01:26

is there a vue way of React.createElement (How to pass vue element to child component through props)?

I know this is weird. In react, I can create an element using var ele = React.createElement(...); then I can pass it to
讨论数 3
vue
创建时间:2016-01-28 06:16:58

require src/src/util/index.js error with babel6

Module parse failed: /Users/Jokcy/workspace/office/vue-example/node_modules/babel-loader/index.js!/Users/Jokcy/workspace
讨论数 2
vue
创建时间:2016-01-28 02:54:43

Passing Data with props question

This issue has been a pain and can't seem to get it working properly. Some background, i'm using the modular approach wh
讨论数 3
vue
创建时间:2016-01-27 21:07:17

watcher.run

watcher:run 这个方法叫diff是不是更合适一些 事实上你只是把wacher放入队列中,但是还是在做diff的工作
讨论数 2
vue
创建时间:2016-01-27 16:12:25

Watch.deep not working as expected

I'm running into an issue with watch using the deep: true option. I have the following component: MyComponent = Vue.exte
讨论数 10
vue
创建时间:2016-01-27 16:01:00

<template v-if=''>

这种形式不能弄简单点儿么 就直接 < v-if='' >< v > 这样不行么
讨论数 5
vue
创建时间:2016-01-27 10:28:11

how to pass props to child through a directive

I want to custom a directive for dealing with props passing from parent to child. I didn't find much information from th
讨论数 7
vue
创建时间:2016-01-27 07:57:17