Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slot必须和父元素的开始标签隔字符才可以解析成功 #801

Closed
songkeys opened this issue Jan 19, 2018 · 6 comments
Closed
Assignees

Comments

@songkeys
Copy link

songkeys commented Jan 19, 2018

// parent.wpy
<child>Something</child>

// child.wpy
// 解析正确,但这会导致多余的空格:" Something"
<template>
  <view> <slot></slot></view>
</template>

// 解析错误,view 整个消失
<template>
  <view><slot></slot></view>
</template>

Edited:
现在发现隔字符就能解析,所以这样解决了:

<template>
  <view>{{}}<slot></slot></view>
</template>
@songkeys songkeys changed the title slot必须和父元素的开始标签隔一个空格或换行等空字符才可以解析成功 slot必须和父元素的开始标签隔字符才可以解析成功 Jan 19, 2018
@Gcaufy Gcaufy self-assigned this Jan 19, 2018
@Gcaufy
Copy link
Collaborator

Gcaufy commented Jan 19, 2018

使用一模一样的代码但是并没有复现问题。

@songkeys
Copy link
Author

songkeys commented Jan 19, 2018

@Gcaufy
我这边还是有问题,下面是我测试的代码:

// child.wpy
<template>
  <view class="red"><slot></slot></view>
</template>

<script>
import wepy from 'wepy'

export default class Child extends wepy.component {}
</script>

<style>
.red {
  background-color: #f00;
}
</style>
// parent.wpy
<template>
    <child>Hello.</child>
</template>

<script>
import wepy from 'wepy'
import Child from './child'

export default class Parent extends wepy.page {
  components = {
    child: Child
  }
}
</script>

<style></style>

期望看到的是红底的 Hello,但实际效果是只有 Hello,外层 view 消失了。在子组件复杂嵌套情况下,还可能导致各种丢失元素。

@Gcaufy
Copy link
Collaborator

Gcaufy commented Jan 24, 2018

这是xmldom的一个BUG,已提交PR,jindw/xmldom#229
但貌似这个项目现在不怎么维护了。所以这个问题可能展示无法修复。
在下个版本中可能会弃用xmldom来作DOM解析。

@Gcaufy Gcaufy closed this as completed Jan 24, 2018
@fantasy525
Copy link

fantasy525 commented Feb 1, 2018

我在自定义组件标签中放入了另外一个自定义组件作为slot,结果只渲染了slot的内容,外层的东西全没了,加了{{}}也不行 @songkeys,还有其他办法吗

@songkeys
Copy link
Author

songkeys commented Feb 2, 2018

@fantasy525 可以看一下上面提到的 PR 里的修复办法,自己在本地改一下 xmldom 的源码。

@asins
Copy link

asins commented Aug 22, 2018

我也遇到这个问题,现在解决办法是加入换行符解决,比如

这样定义的组件,在wepy编译后,button标签没有了
<button class="my-class" bindtap="onNeedLogin"><slot></slot></button>

这样写正常了~~~~

<button class="my-class" bindtap="onNeedLogin">
  <slot></slot>
</button>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants