baidu / san

A fast, portable, flexible JavaScript component framework
https://baidu.github.io/san/
MIT License
4.72k stars 549 forks source link

条件判断 s-else 节点缺失 props class #727

Closed kanglover closed 2 years ago

kanglover commented 2 years ago

通过组件声明的 props class 属性,默认会加子组件的首个节点 class 属性中。如:

<child class='propClass'>

var child = san.defineComponent({
    template: '<div class="originClass"><p>Hello</p></div>'
});
===>渲染结果
<div class="originClass propClass"><p>Hello</p></div>

但 san 貌似没有考虑到 s-if/s-else 的情况(Vue 类似能力没问题)

<child class='propClass'>

var child = san.defineComponent({
    template: `
        <p s-if="isShow">Hello if</p>
        <p s-else>Hello else</p>`,

    initData: function () {
        return {
            isShow: false,
        };
    }
});
===>渲染结果
<p>Hello else</p>

写了个在线 demo 示例可以查看:https://codepen.io/kanglover/pen/rNdezaj


看代码是 Element attach 时, else aNode 的 props 为空数组 https://github.com/baidu/san/blob/master/src/view/element.js#L143

errorrik commented 2 years ago

fixed