slot内容分发

slot: 位置;狭槽;水沟;硬币投币口 ---from有道词典
个人理解为位置预占, 有新增则覆盖, 无则显示预占内容

一、 默认情况




此时 i am tangerine 不会显示 由于children组件中并未设置插槽。

二、单个slot




此时 i am tangerine 将替换整个标签进行渲染 如果无 i am tangerine 将会显示默认内容 i am slot without name

二、具名slot




经测试多个相同slot名的元素将依次插入对应的预占位置,无slot名的元素依次插入无name值的slot位置,即表现为

i am children i am tangerine i am orange i am apple who am i ? who are you ?

三、实例

一个具有默认显示的组件
当我们想要有 Success、Warning、Error 等不同样式和不同内容的 alert 时,我们会希望这样使用:

    
      success:  this is some info about success;
    
    
      wraning:  this is some info about wraning;
    
    
      error:  this is some info about error;
    

要实现这个功能 具体如下:
Alert.js




app.js




四、进阶 - 结合render函数

预知后事如何,且听下回分解

你可能感兴趣的:(slot内容分发)